Strangely, if I do this before the second save, it saves:

  ...
  foo.title = 'my_new_title
  foo.username = '%s' % ('awesome_user')
  foo.save()

But if I don't explicitly copy 'awesome_user' into a string then save,
it saves username as the user id.  I should also note that  foo.id
from my previous post is a ForeignKey to the users table.  I'm
guessing it's getting stepped on b/c of that, but I'm not sure if it's
a bug or just bad practice on my part.


On Apr 15, 10:06 pm, tm <tmugav...@gmail.com> wrote:
> Hello, I just updated to the latest django dev version and it changed
> the behavior of my code (not suprisingly :)  Get data from a form,
> save it to the DB, then in the same save function get the id from what
> was just saved, update a values and save it again.  I need to do this
> to get the id of what was just saved, so I can update a field in that
> record based on that ID  Now instead of maintaining the username on
> the second save, it overwrites it with the user_id.  Here is the an
> outline of the code that used to work:
>
> class EditFooForm(ModelForm):
>   class Meta:
>     model = Foo
>
> def save(self, <some args passed in>):
>   foo = Foo()
>   foo.id = some_user_id
>   foo.username='awesome_user'
>   foo.title = 'my great title'
>   foo.submit_date=datetime.datetime.now()
>   foo.save()
>
>   # We're OK here!
>   # The DB has username as 'awesome_user' and user_id as '1234'
>
>   my_new_title = '%s_%s' % ( foo.id, some_file_name  )
>   foo.title = my_new_title
>   foo.save()
>
>   #Issue:  username for that record in the DB is now '1234'
>
> I am by no means a Django expert, but this code has worked for months
> so I'm sure I'm missing something simple.  Any help would be greatly
> appreciated!
>
> Thanks,
>
> T
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to