I am new to Django/python and I am helping the team in migrating Django project as the installed server needs to be migrated.
Old Version
Django - 1.6.5
Python - 2.7
Due to some compatibility and versions not available, below the versions which we migrated to and was able to bring up the application without any errors. There were some compilation error related to deprecated methods and was able to correct that.
Migrated Version
Django - Django-1.6.5
Python – 3.4
Database – sqllite
Pillow - Pillow-3.3.0
PIP - pip-1.5.4
Everything looks fine, except the admin module. In the main admin screen instead of displaying the module fields, it is just displaying the object name.
Below the location model list it used to display before migration
Room: A | Cabinet: 23 | Drawer: 7
Room: A | Cabinet: 24 | Drawer: 4
After Migration, it just displays the location object name
Location object
Location object
**class Location(models.Model):
room = models.CharField(max_length=31,
help_text='(Required) e.g. A, B, C, D, E, F')
station = models.IntegerField(max_length=5,
blank=True,
null=True,
help_text='e.g. 1, 2, ...')
cabinet = models.IntegerField(blank=True,
null=True,
help_text='e.g. 1, 2, ...')
shelf = models.IntegerField(blank=True,
null=True,
help_text='e.g. 1, 2, ...')
drawer = models.IntegerField(blank=True,
null=True,
help_text='e.g. 1, 2, ...')
map = models.ImageField(upload_to='location_maps',
blank=True,
null=True)
class Meta:
unique_together = (('room', 'station', 'cabinet' ,'shelf', 'drawer'),)
def __unicode__(self):
string = 'Room: {}'.format(self.room)
if self.station:
string += ' | Station: {}'.format(self.station)
if self.cabinet:
string += ' | Cabinet: {}'.format(self.cabinet)
if self.shelf:
string += ' | Shelf: {}'.format(self.shelf)
if self.drawer:
string += ' | Drawer: {}'.format(self.drawer)
return string*
Below the configuration for admin.py
*from django.contrib import admin
from mgmt.models import *
admin.site.register(Location)*
Any help would be really appreciated as I am not seeing any code change in the admin.py to make any correction
Below the Table
*CREATE TABLE "mgmt_location" (
"id" integer NOT NULL PRIMARY KEY,
"room" varchar(31) NOT NULL,
"station" integer,
"cabinet" integer,
"shelf" integer,
"drawer" integer,
"map" varchar(100),
UNIQUE ("room", "station", "cabinet", "shelf", "drawer")
)*
try replacing def __unicode__():
with def __str__():
as
in Python 2, def __unicode__():
had been used to determine the human-readable representation of an object.But in Python 3, it's has been replaced with def __str__():