Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#302 closed defect (fixed) doesn't update, re-inserts

Reported by: Manuzhai Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: paul.bowsher@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Probably something to do with [462]. My model:

class Post(meta.Model):
    fields = (
        meta.MZSlugField('slug', 'slug', prepopulate_from = ('title',)),
        meta.CharField('title', 'title', maxlength = 255),
        meta.DateTimeField('datetime', 'date created'),
        meta.DateTimeField('modified', 'date modified'),
        meta.TextField('content', 'post'),
        meta.ManyToManyField(Tag, filter_interface = meta.HORIZONTAL),
    admin = meta.Admin(
        fields = (
            (None, {'fields': ('title', 'slug', 'datetime', 'content', 'tags')}$
        list_display = ('title', 'datetime', 'display_tags'),
        list_filter = ('datetime', 'tags'),
    ordering = ('-datetime',)
    def __repr__(self):
        return self.title
    def display_tags(self):
        return ' '.join([obj.tag for obj in self.get_tag_list()])
    display_tags.short_description = 'Tags'

I'm doing this with the API, from the interactive interpreter.

Change History (9)

comment:1 Changed 13 years ago by Adrian Holovaty

Could you paste in the API code you used to save? Our unit tests are passing, so I suspect your API calls might be strange.

comment:2 Changed 13 years ago by Manuzhai

Was really basic, something like this:

>>> from django.models.posts import posts, tags
>>> mv = tags.get_object(tag__exact = 'movies')
>>> post = posts.get_object(slug__exact = 'you-stupid-man')
>>> post.set_tags([])

This is with [473].

comment:3 Changed 13 years ago by Jacob

Why are you calling save() twice?

comment:4 Changed 13 years ago by Manuzhai

That was to test that it was inserting another time. That shouldn't re-insert the object, though, should it?

comment:5 Changed 13 years ago by Adrian Holovaty

You don't need to call after calling post.set_tags().

You only need to save fields on the object itself. It has no effect on related objects.

comment:6 Changed 13 years ago by Manuzhai

Okay, that actually makes sense. But still, why is it re-inserting?

comment:7 Changed 13 years ago by Boffbowsh

Cc: paul.bowsher@… added

I'm getting a similar problem with the admin interface. If nothing has changed and then you hit save, it tries to reinsert, but fails as my primary key isn't an autofield

class Player (meta.Model):
	fields = (
		meta.IntegerField('profileid', primary_key=True),
		meta.CharField('realname', maxlength=32, blank=True),
		meta.CharField('ingamename', maxlength=32, db_index=True, unique=True),
		meta.ForeignKey(Team, blank=True),
		meta.ForeignKey(Server, name="lastseenon")

	def __repr__(self):
		return self.ingamename
	admin = meta.Admin(
			search_fields = ['ingamename', 'profileid'],

comment:8 Changed 13 years ago by Manuzhai

I think this is probably fixed as a result of [507], see also #320.

comment:9 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

Good call, Manuzhai. This should be fixed now.

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