0

I'm working on my first Django project and employing django-registration and django-profiles. The former worked beautifully with nary an issue. The second has been a bit more problematic.

After many hours, specific user profiles can finally be viewed, which is terrific, along with a list of all profiles.

The two issues I'm encountering: django-profiles will not automatically create a new profile when a new user is created. Once a user is created in the admin, a profile should be created. That isn't occurring.

In addition, the profiles/edit_profile form results in this error:

"TemplateSyntaxError at /profiles/edit/ Caught NoReverseMatch while rendering: Reverse for 'edit_profile' with arguments '(,)' and keyword arguments '{}' not found."

I've searched for answers to these issues to no avail.

This is the model for the profile in my app file:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    first_name = models.CharField(max_length=25)
    last_name = models.CharField(max_length=35)
    email = models.EmailField()
    birth_date = models.DateField(blank=True, null=True)
    city = models.CharField(max_length=25)
    state = models.CharField(max_length=20)
    zip_code = models.CharField(max_length=10)

    def __unicode__(self):
        return " %s" % (self.user)

    def get_absolute_url(self):
        return ('profiles_profile_detail', (), { 'username': self.user.username })
    get_absolute_url = models.permalink(get_absolute_url)

This is my form:

class ProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile

This is the template:

{% extends 'base.html' %}
{% block page_title %}Edit Profile{% endblock %}

{% block headline %}Edit Stentorian Profile{% endblock %}

{% block content %}

 <form action="{% url edit_profile user %}" method="post">{% csrf_token %}
 {{ form.as_p }}
 <input type="submit" value="Submit" />
 </form>

 {% endblock %}

Interested in learning what errors I made and how to fix these. (I realize the user object carries first and last name, but there appears no other way to insert these into the profile other than with their own specific fields).

Any insight appreciated.

Edit: It seems to have worked out thanks to The Missing Manual. Unfortunately, /profiles/edit now bounces to /profiles/create. Not sure of this issue.

Why Not
  • 603
  • 3
  • 14
  • 25
  • To create a `UserProfile` automatically, look at django's docs: https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users . You can use a post save signal to generate the profile. As for the `NoReverseMatch`, it sounds like you don't have URL set up to handle the permalink you specified. You need to make sure you've `include`ed the django-profiles urls.py – Yuji 'Tomita' Tomita Feb 12 '12 at 01:22
  • I have included the urls file: url(r'^profiles/', include('profiles.urls')), Thanks for the other info. I'll try that immediately. As I said, viewing a specific profile and a list works. It's just the form in the template that's giving fits. – Why Not Feb 12 '12 at 01:25

1 Answers1

0

Here is a link to help you with this.

django-profiles the missing manual

Scroll down to NO MISSING PROFILES! section. Here they explain that to create a profile must be done with a signal whenever a User instance is created.

darren
  • 18,845
  • 17
  • 60
  • 79