1
try adding id=i
in c = City()
. So that every time you create a new one, the id is adding 1 to it.
c = City(id=i, name=line[1], uniqueID=i,
xcoord=int(line[3]), ycoord=int(line[2]),
country=line[4],
population=line[5], times_played=line[6], average_distance=line[7],
difficulty_rating=line[8])
1
id
in Your model has type AutoField. This type of firld automaticaly increment values when new row is added.
You can overwrite id
when You create a new row
c = City(id=1, name='test', ...)
c.save()
City.objects.get(pk=1)
or read inserted id
after save model
c = City(name='test', ...)
c.save()
lastId = c.pk
City.objects.get(pk=lastId)
- [Answered ]-Change default form for field in django
- [Answered ]-Django – ManyToManyField is not shown in Form
- [Answered ]-Python Django populate() isn't reentrant
- [Answered ]-Revelants queries suggestion for autocomplete with Solr
- [Answered ]-Django random sort list
Source:stackexchange.com