Python/Django TangoWithDjango Models and Databases

后端 未结 3 857
别跟我提以往
别跟我提以往 2021-01-23 07:03

I\'m currently following http://www.tangowithdjango.com and I\'m trying to populate an existing DB with populate_rango.py. When I create the new categories, I\'m tr

3条回答
  •  悲&欢浪女
    2021-01-23 07:24

    The following worked for me, when added to populate_rango.py -

    def add_cat(name, views, likes):
        c = Category.objects.get_or_create(name=name)[0]
        c.views = views
        c.likes = likes
        c.save()
        return c
    

    The difference might be due to c.save()

提交回复
热议问题