How to get an object for editing transfer to a form?

38 views Asked by At

I don't know how to get my announcement to insert into the form for editing. How to insert existing data into the form for editing? i try use include. i don't understand how get edit form. and i have another one question: how to make favorites announcement without js? help me please

my model:

class Announcement(models.Model):
    category = models.CharField(choices=professions, blank=False)
    title = models.CharField(max_length=40, blank=False)
    slug = models.SlugField(max_length=250, unique_for_date='publish', )
    price = models.IntegerField(default=None, null=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='announcement_work')
    publish = models.DateTimeField(auto_now_add=True)
    description = models.TextField(max_length=500, blank=False)
    company = models.CharField(max_length=30, blank=False)
    experience = models.CharField(choices=Experience, blank=False)
    address = models.CharField(max_length=30, blank=False)
    city = models.CharField(max_length=30, blank=False)
    country = models.CharField(max_length=30, blank=False)
    Favorites = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='Favorites', blank=True)

    class Meta:
        ordering = ['-id']
        indexes = [
            models.Index(fields=['-id'])
        ]

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('account:announcement_detail', args=[self.publish.year,
                                                            self.publish.month,
                                                            self.publish.day,
                                                            self.slug])

    tags = TaggableManager()

my form

class AnnouncementForm(forms.ModelForm):
    class Meta:
        model = Announcement
        fields = ['category', 'title', 'price',
                  'country', 'city', 'description',
                  'experience', 'company', 'address', 'tags']

i try write views and url, but see error: django.urls.exceptions.NoReverseMatch: Reverse for 'announcement_edit' with no arguments not found. 1 pattern(s) tried: ['account/(?P<announcement_id>[0-9]+)/edit/\Z'] [26/Mar/2024 22:21:09] "GET /account/2024/3/21/employer-and-user/ HTTP/1.1" 500 154441 django.urls.exceptions.NoReverseMatch: Reverse for 'announcement_edit' with no arguments not found. 1 pattern(s) tried: ['account/(?P[0-9]+)/(?P[0-9]+)/(?P[0-9]+) /(?P[-a-zA-Z0-9_]+)/edit/\Z'] i try transmit data to url : '{% url 'account:announcement_edit' year month day slug %}'

0

There are 0 answers