python 2.7 - App_Model does not exist in django -
i new django , have bit of problem. creating simple view, template , models small project. getting error vote_type not exist, when asking type model in 'vote' app. don't why looking vote_type instead of type in database.
so went problem , tried create object of model type in database python console got same error.
this models:
from django.db import models django.utils import timezone # create models here. class voted_object(models.model): voted_object_name = models.charfield(max_length=50) voted_object_image = models.imagefield voted_object_rating = models.integerfield(default=0) voted_object_id = models.integerfield class type(models.model): pub_date = models.datetimefield('date published') type_name = models.charfield(max_length=50) type_id = models.integerfield
and error when try type.objects.all() in python console.
relation "vote_type" not exist line 1: ...te_type"."pub_date", "vote_type"."type_name" "vote_type..
what wrong code? why django looking vote_type instead of type
by default django creates tables naming scheme "{app_name}_{class_name}
" - expecting find table called "vote_type" in database corresponds type
model in vote
app. did create , run migrations add table, or manually?
unrelated, can suggest structure app this:
from django.db import models django.utils import timezone # create models here. class vote(models.model): name = models.charfield(max_length=50) image = models.imagefield() rating = models.integerfield(default=0) class votetype(models.model): pub_date = models.datetimefield('date published') name = models.charfield(max_length=50)
- you don't need
id
fields - they're added automatically - prefixing field names makes things verbose.
vote.name
easier write/understandvote.voted_object_name
. same_object
suffix. type
keyword, maybe usevotetype
instead.
Comments
Post a Comment