The method create_profile returns profile after saving. But this object will not contain primary keys etc generated in the db. To work around this common issue with django
profile.save() # Get the data again from db. profile = Profile.objects.get(user=username) return profile Let me know if this helps. On Aug 1, 8:59 pm, zayatzz <alan.kesselm...@gmail.com> wrote: > I figured ill add the code i have so far: > > The models: > class ProfileManager(models.Manager): > def create_profile(self, username): > "Creates and saves a User with the given username, e-mail and > password." > now = datetime.datetime.now() > profile = self.model(user=username) > profile.save() > return profile > > class Profile(models.Model): > """ Profile model """ > user = models.ForeignKey(User, unique=True) > birth_date = models.DateField(help_text="birth date", > verbose_name="Birth date", blank=True, null=True, ) > gender = models.PositiveSmallIntegerField(help_text="gender", > choices=GENDER_CHOICES, blank=True, null=True) > about = tinymce_models.HTMLField(blank=True, null=True, > help_text="Write something about yourself here", > verbose_name="Something about yourself") > # contacts - email, phone nr, website, image > img = models.ImageField(upload_to=upload_location, blank=True, > null=True, verbose_name="Your mugshot") > website = models.CharField(max_length=200, blank=True, null=True, > help_text="Do you have personal website or blog? Promote it by > entering it here", verbose_name="Your Website address") > phonenr = models.CharField(max_length=30, blank=True, null=True, > help_text="Your office or home phone number", verbose_name="Your home > or office number") > mobilenr = models.CharField(max_length=30, blank=True, null=True, > help_text="Your mobile phone number", verbose_name="Your mobile phone > nr") > #Full profile - adress will be visible too > country = models.PositiveIntegerField(choices=COUNTRY_CHOICES, > blank=True, null=True) > address1 = models.CharField(max_length=200, blank=True, null=True, > help_text="Address info - street and house/apartment number") > address2 = models.CharField(max_length=200, blank=True, null=True, > help_text="Address info - town and areacode") > address3 = models.CharField(max_length=200, blank=True, null=True, > help_text="Address info - county") > publicprofile = models.PositiveSmallIntegerField(help_text="Profile > type", choices=PROFILE_CHOICES, blank=True, null=True) > newsletter = models.BooleanField(help_text="Do you want to recieve > our newsletter?", verbose_name="Do you want our newsletter", > blank=True, null=True) > objects = ProfileManager() > > The Form: > class ProfileForm(ModelForm): > about = forms.CharField(widget=TinyMCE(attrs={'cols': 40, 'rows': 15, > 'theme':"simple"}), label = "Something about yourself") > class Meta: > model = Profile > fields = ('gender', 'birth_date', 'about', 'img', 'website', > 'phonenr', 'mobilenr', 'country', 'address1', 'address2', 'address3', > 'publicprofile', 'newsletter', ) > > The view: > def profile_edit(request): > if request.user.is_authenticated(): > message = "default" > try: > profile = Profile.objects.get(user=request.user) > except: > profile = Profile.objects.create_profile(request.user) > if request.method == 'POST': > pform = ProfileForm(request.POST, instance=profile) > if pform.is_valid(): > pform.save() > message = "form vas saved" > else: > message = "form not valid" > else: > #dict vaja saata uue formiga > message = "new form" > pform = ProfileForm(instance=profile) > context = { 'message':message, 'pform':pform, } > return render_to_response('profile/profile_detail.html', > context, > context_instance=RequestContext(request)) > else: > return HttpResponseRedirect("/accounts/login/") > > What i see in view after posting is - form not valid > > I really could use help figuring out, why it is not valid. > > Alan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---