django - Retrieve ModelForm pk after save -


models:

class users(models.model):       first_name = models.charfield(max_length=50)     last_name = models.charfield(max_length=50)     email = models.charfield(max_length=100)  class event(models.model):     event_admin = models.foreignkey(users)     event_name = models.charfield(max_length=50)     event_location = models.charfield(max_length=50)     event_date = models.datefield()     event_time = models.timefield()     event_notes = models.charfield(max_length=200) 

view:

 if request.method == 'post':             eventform = createeventform(request.post,prefix = "eventform")     userform = userinfoform(request.post, prefix = "userform")             if eventform.is_valid() , userform.is_valid():                      userform.save()          #problem here         retrieveid= userform.id          event1 = eventform.save(commit=false)                     event1.event_admin= retrieveid         event1.save() 

i have 2 modelforms posting 1 form. after 1st 1 saves, im trying id/pk save foreign key field in second form. however, error attribute doesnt exist.

userform.save() return newly created object, it:

obj = userform.save() 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -