lambdalisue / django-inspectional-registration

Django registration app with Inspection before activation
http://pypi.python.org/pypi/django-inspectional-registration
42 stars 26 forks source link

Can not override __str__ in RegistrationSupplementBase #67

Closed theilgaard closed 8 years ago

theilgaard commented 8 years ago

When trying to override the __str__ function

class RegistrationSupplement(RegistrationSupplementBase):
    firstname = models.CharField("First name", max_length=100, help_text="Please fill in your first name")
    lastname = models.CharField("Last name", max_length=100, help_text="Please fill in your last name")
    affiliation = models.CharField("Affiliation", max_length=100, help_text="Please fill in your affiliation")
    pi = models.CharField("Principal Investigator", max_length=100,
                          help_text="Please fill in your Principal Investigator")
    remarks = models.TextField("Remarks", blank=True)

    def __str__(self):
        return "%s %s, %s".format(self.firstname, self.lastname, self.affiliation)

I get the exception raised from the Base class. I have set the REGISTRATION_SUPPLEMENT_CLASS in settings.py and can see the additional supplement fields on the register page.

When I want to see the Registration Profiles on the admin page, I get the exception

NotImplementedError at /admin/registration/registrationprofile/
You must define '__str__' method and return summary of the supplement
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/registration/registrationprofile/
Django Version: 1.9.7
Exception Type: NotImplementedError
Exception Value:    
You must define '__str__' method and return summary of the supplement
Exception Location: /usr/local/lib/python2.7/site-packages/registration/supplements/base.py in __str__, line 64
Python Executable:  /usr/local/bin/python
Python Version: 2.7.11
Python Path:    
['/code',
 '/usr/local/lib/python27.zip',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/usr/local/lib/python2.7/lib-old',
 '/usr/local/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/site-packages']
Server time:    Thu, 23 Jun 2016 13:42:12 +0200
lambdalisue commented 8 years ago

Hum... It is really strange. Could I see your entire project? I would like to download and see what's going on.

theilgaard commented 8 years ago

I uploaded my codebase here https://github.com/theilgaard/asdctest

lambdalisue commented 8 years ago

Sorry for late reply, I'll check it.

theilgaard commented 8 years ago

All good. Could you reproduce the issue?

lambdalisue commented 8 years ago

Sorry for late reply. I had been troubled with installing psycopg2 but now the problem has solved.

I modified default database to SQLite and I could not reproduce your situation.

selection_002 selection_003

I used Python 3 so I wonder if https://docs.djangoproject.com/en/1.9/topics/python3/#str-and-unicode-methods helps to solve your problem.

theilgaard commented 8 years ago

Thanks a lot! I'm using python 2.7 and annotating my class with the following worked.

@python_2_unicode_compatible