0

I made something like this :

models.py

from django.db import models
from django.utils.encoding import smart_text
class SignUp(models.Model):
    first_name=models.CharField(max_length=100,null=True,blank=True)
    second_name=models.CharField(max_length=100,null=True,blank=True)
    email=models.EmailField(max_length=100)
    casPridania=models.DateTimeField(auto_now_add=True,auto_now=False)
    casAktualizacie=models.DateTimeField(auto_now_add=False,auto_now=True)

    def __unicode__(self):
        return smart_text(self.first_name)

admin.py

from django.contrib import admin
from .models import SignUp
class prihlasenieAdmin (admin.ModelAdmin):
    class Meta:
        model=SignUp

admin.site.register(SignUp,prihlasenieAdmin)

It looks fine, but when I log on my page with /admin and make a new sign up, it doesn't return first name, it returns "Sign up object". I tried to return email and now first_name, but nothing worked.

//Solved by using __str__ instead of __unicode__ in module.py

Susurka
  • 1
  • 1
  • Which version of Python are you using? If Python 3 then it might be a duplicate of http://stackoverflow.com/questions/16121815/django-tutorial-unicode-not-working. – sthzg Jan 12 '15 at 15:51
  • curious; why __str__ for Python 3, and __unicode__ for Python 2.7? – warath-coder Jan 12 '15 at 16:53
  • 1
    @warath-coder I think this (http://stackoverflow.com/a/18034409/870769) is a wonderful write-up that despite being short helps a lot in understanding Python's string-mysterium. So, basically, in Python 3, ``str`` is what used to be ``unicode`` in Python 2. – sthzg Jan 12 '15 at 18:21

1 Answers1

3
def __str__(self):
    return self.first_name
karthikr
  • 97,368
  • 26
  • 197
  • 188
django-renjith
  • 3,280
  • 2
  • 13
  • 16