Jun-02-2018, 11:43 AM
I am setting up a command to runfrom the command line to put some initial values in the database, but for some reason the model is not getting saved. I have set up the command as per here (but with no args):
https://docs.djangoproject.com/en/dev/ho...-commands/
Here is my class, with a few print commands for debugging. The reset method goes on to add objects, but that fails because they belong to the universe, and that no id:
I am only just learning Django/Python, but have a fair bit of experience with Ruby on Rails; nevertheless this has me stumped.
Python 3.6.5/Django 2.0.5 final/Windows 10
https://docs.djangoproject.com/en/dev/ho...-commands/
Here is my class, with a few print commands for debugging. The reset method goes on to add objects, but that fails because they belong to the universe, and that no id:
class Universe(models.Model): name = models.CharField(max_length=200) turn_count = models.IntegerField(default=0) def __str__(self): return self.name def reset(): universe = Universe(name='Testiverse') print(universe) print(universe.id) print("universe turn count is %s." % universe.turn_count) universe.save print(universe.id) print("universe count is %s." % Universe.objects.all().count())The Universe object is created as it should be, but it does not get saved, as show by the count not going up. I can create them via the admin interface, and the count is reported correctly.
I am only just learning Django/Python, but have a fair bit of experience with Ruby on Rails; nevertheless this has me stumped.
Python 3.6.5/Django 2.0.5 final/Windows 10