Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#302 closed defect (fixed)

object.save() 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: no UI/UX: no

Description

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 by Adrian Holovaty, 19 years ago

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 by Manuzhai, 19 years ago

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([mv.id])
>>> post.save()
>>> post.save()

This is with [473].

comment:3 by Jacob, 19 years ago

Why are you calling save() twice?

comment:4 by Manuzhai, 19 years ago

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

comment:5 by Adrian Holovaty, 19 years ago

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

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

comment:6 by Manuzhai, 19 years ago

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

comment:7 by Boffbowsh, 19 years ago

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.IntegerField('bookingid'),
		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 by Manuzhai, 19 years ago

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

comment:9 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

Good call, Manuzhai. This should be fixed now.

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