Opened 12 years ago

Closed 12 years ago

#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 Claude Paroz)

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()

Change History (3)

comment:1 by molavy, 12 years ago

db :sqlite

comment:2 by Claude Paroz, 12 years ago

Description: modified (diff)

Please use preview and proper formatting.

comment:3 by Claude Paroz, 12 years ago

Resolution: needsinfo
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top