Code

#19330 closed Bug (needsinfo)

change model instance with unique_together using modelform

Reported by: molavy Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords: modelform ,unique_together ,instance ,save, change
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by claudep)

I have Problem on changing a model with modelform and instance
model form return form validate error:
user with this title already exist

model:

class Tag(models.Model):
    user = models.ForeignKey(User)
    title = models.CharField(max_length=765)
    create_time = models.DateTimeField(null=True, blank=True)
    status = models.IntegerField(null=True, blank=True)
    color = models.CharField(max_length=765, blank=True)
    cnt_member = models.IntegerField(null=True, blank=True)
    cnt_items = models.IntegerField(null=True, blank=True)
    def __unicode__(self):
        return self.title+ " || "+self.user.username
    class Meta:
        db_table = u'tbl_tag'
        unique_together=("user","title")

form:

class Tagform(forms.ModelForm):
    
    class Meta:
        model=Tag
        exclude = ('status','create_time')

view:

def change_tag_title(request):
    if request.POST and request.is_ajax():
        cur_id=request.POST["id"]
        cur_tag=Tag.objects.get(id=cur_id,user=request.user)
        cur_req=request.POST.copy()
        cur_req['user']=request.user.id
        cur_form=Tagform(data=cur_req, instance=cur_tag)
        if cur_form.is_valid():
            cur_form.save()

Attachments (0)

Change History (3)

comment:1 Changed 17 months ago by molavy

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

db :sqlite

comment:2 Changed 17 months ago by claudep

  • Description modified (diff)

Please use preview and proper formatting.

comment:3 Changed 17 months ago by claudep

  • Resolution set to needsinfo
  • Status changed from new to closed

I'm afraid we have not enough information in the ticket description to assume that there is a bug in Django. Please try to debug the problem a little further and tell us why you think the problem is in Django and not in your code.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.