Use Database View in Django

I saw a question whether I can use the database view as a model in django and try it in my application, but this did not work.

I created the view with the name "vi\_topics"manually and it had a column "id", but I still got the error, even if I added the kernel explicitly "id", saying

"no such column: vi_topics.id"

Here is the definition of my model with the name Vitopic:

from django.db import models

class Vitopic(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    author_name = models.CharField(max_length=200)
    author_email = models.CharField(max_length=200)
    view_count = models.IntegerField(default=0)
    replay_count = models.IntegerField(default=0)
    tags = models.CharField(max_length=255)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'vi_topics'

Note . I am using sqlite3.

+3
source share
2 answers

: http://docs.djangoproject.com/en/dev/ref/models/options/#managed

Options.managed

Django 1.1: .

True, Django syncdb reset. Django .

False, . , , . , False. .

  • , . , , , .
  • managed = False ManyToManyField, , "--" . .

    , - ( ) ManyToManyField.through, .

, = False, , .

+3

id = models.IntegerField(primary_key = True)

+1

Source: https://habr.com/ru/post/1711227/


All Articles