From your URLs, it looks like you have a view Project
which is clashing with the model Project
.
path('project/<pk>/', login_required(views.Project.as_view()), name='projects-project'),
so I'm pretty new to Django and for the life of me can't seem to figure out what's going on here. I had a form working and showing up in a webpage, and I was able to get a database to be created and show up in SQL. However, when I tried to get the forms to save the information into the database, the fields I began testing with have disappeared and nothing is written to the database., 1 week ago In this example, Bar doesn't exist at the time that the whiz attribute is defined. To allow you to reference a model before it is declared, Django lets you use the string form. String form … , 1 day ago get_or_create returns a tuple of (instance, created) where the second element is a boolean showing whether or not the operation resulted in a new item being created. You should … , 1 week ago In Example 2, I’ll show how to fix the AttributeError: type object ‘datetime.datetime’ has no attribute ‘datetime’. To resolve the problem, we just have to “import datetime” instead of “from …
from django.db
import models class Team(models.Model): team_number = models.IntegerField() team_name = models.CharField(max_length = 30) robot_weight = models.FloatField() robot_height = models.IntegerField() team_location = models.CharField(max_length = 30) team_notes = models.CharField(max_length = 150) posted_on = models.DateTimeField('Posted On') def __unicode__(self): return self.team_number class Meta: db_table = 'teams'
app_label = 'frcstats'
installed using pip install django-pb-model (via nix),macOS Mojave (v10.11.5),@Krajiyah What's your django-pb-model version? I can't reproduce on my local with version 0.1.8,Sorry I am using the django 2.2.7 I get the same error with your test model when are you going to make this awesome work, work with newer version of django?
from django.db
import models
from pb_model.models
import ProtoBufMixin
import somemessage_pb2
class SomeModel(ProtoBufMixin, models.Model):
pb_model = somemessage_pb2.SomeMessage
pb_2_dj_fields = '__all__'
someKey = models.CharField(
primary_key = True,
editable = False,
db_index = True,
max_length = 100
)
class BugFixedMeta:
def __init__(self):
self.app_label = 'myapp'
self.object_name = 'SomeModel'
class BugFixedProtoBufMixin(ProtoBufMixin):
def __init__(self):
super(ProtoBufMixin, self)
self._meta = BugFixedMeta()
class SomeModel(BugFixedProtoBufMixin, models.Model):
#...same as before...
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/management/base.py", line 350, in execute
self.check()
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/nix/store/3rh5qb6si5d1v8fqdfzz165zsxms6fgv-python3-3.7.2-env/lib/python3.7/site-packages/django/core/checks/model_checks.py", line 17, in check_all_models
if not inspect.ismethod(model.check):
AttributeError: type object 'BugFixedProtoBufMixin' has no attribute 'check'
class PBCompatibleModel(ProtoBufMixin):
...
From your URLs, it looks like you have a view Project which is clashing with the model Project.,Django GCBV UpdateView AttributeError - type object 'QuerySet' has no attribute '_meta',AttributeError in views.py: type object 'Transaction' has no attribute 'objects',Django1.9 AttributeError at /books/ type object 'Books' has no attribute 'Objects'
From your URLs, it looks like you have a view Project
which is clashing with the model Project
.
path('project/<pk>/', login_required(views.Project.as_view()), name='projects-project'),
The problem is in your forms.py. See you anycodings_django have this model import:,And then you define the Team form anycodings_django shadowing the imported model:,and then use it to set the model on the anycodings_django model form:,Then, when you use model = Team inside anycodings_django the TeamForm it would actually use the anycodings_django Team form reference and not the imported anycodings_django model.
models.py
from django.db
import models
class Team(models.Model):
team_number = models.IntegerField()
team_name = models.CharField(max_length = 30)
robot_weight = models.FloatField()
robot_height = models.IntegerField()
team_location = models.CharField(max_length = 30)
team_notes = models.CharField(max_length = 150)
posted_on = models.DateTimeField('Posted On')
def __unicode__(self):
return self.team_number
class Meta:
db_table = 'teams'
app_label = 'frcstats'
views.py
from django.http import HttpResponseRedirect from django.shortcuts import render from.forms import * def get_name(request): # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: team = Team(request.POST) match = Match(request.POST) auto = Autonomous(request.POST) teleop = Teleoperated(request.POST) # check whether it 's valid: if form.is_valid() and auto.is_valid() and match.is_valid() and teleop.is_valid(): form.save() return HttpResponseRedirect(reverse('frcstats:url')) else: return HttpResponseRedirect('/Form not valid/') # if a GET(or any other method) we 'll create a blank form else: team = Team() auto = Autonomous() match = Match() teleop = Teleoperated() return render(request, 'name.html', { 'team': team, 'auto': auto, 'match': match, 'teleop': teleop, })
forms.py
from django
import forms
from.models
import Team
from django.forms
import ModelForm
class Team(forms.Form):
team_number = forms.IntegerField(label = 'Team Number ')
team_name = forms.CharField(label = 'Team Name ', max_length = 30)
class TeamForm(ModelForm):
class Meta:
model = Team
fields = ['team_number', 'team_name']
class Match(forms.Form):
match_playing = forms.IntegerField(label = 'Match Number ')
The problem is in your forms.py. See you anycodings_django have this model import:
from.models
import Team
And then you define the Team form anycodings_django shadowing the imported model:
class Team(forms.Form):
One way to fix that is to alias your anycodings_django import statement:
from.models
import Team as TeamModel
It seems that the error occurs in django/db/models/fields/related.py, line 624 where self.through.__class__ returns ModelBase whereas prior to 1.2.4 it used to be a user defined class. , Error message is "type object 'ModelBase' has no attribute '_meta'". , There is a problem with using routers in the latest security release 1.2.4. The details are somewhat murky for a lay person but here's the gist of it: , (assuming you have created a registered a router that uses "model._meta.object_name", of course)
- Attempt to save any model with a ManyToManyField fails in router when trying to execute db_for_write:
def db_for_write(self, model, ** hints):
if model._meta.app_label == 'my_app_label':
return 'my_db_name'
return None
Here's the stack trace:
[snip]
File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 375, in save
fail_message, commit, construct = False)
File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 87, in save_instance
save_m2m()
File "/usr/lib/python2.4/site-packages/django/forms/models.py", line 83, in save_m2m
f.save_form_data(instance, cleaned_data[f.name])
File "/usr/lib/python2.4/site-packages/django/db/models/fields/related.py", line 1144, in save_form_data
setattr(instance, self.attname, data)
File "/usr/lib/python2.4/site-packages/django/db/models/fields/related.py", line 730, in __set__
manager.clear()
File "/usr/lib/python2.4/site-packages/django/db/models/fields/related.py", line 506, in clear
self._clear_items(self.source_field_name)
File "/usr/lib/python2.4/site-packages/django/db/models/fields/related.py", line 624, in _clear_items
db = router.db_for_write(self.through.__class__, instance = self.instance)
File "/usr/lib/python2.4/site-packages/django/db/utils.py", line 134, in _route_db
chosen_db = method(model, ** hints)
File "/path/to/my/app/routers.py", line 10, in db_for_write
if model._meta.app_label == 'my_label':
AttributeError: type object 'ModelBase'
has no attribute '_meta'
Same problem here - an easy way to reproduce:
bash-3.2$ ./manage.py shell
Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.auth.models import User
>>> user = User()
>>> user.username = "testuser"
>>> user.save()
>>> user.delete()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/path/to//django/db/models/base.py", line 660, in delete
self._collect_sub_objects(seen_objs)
File "/path/to//django/db/models/base.py", line 625, in _collect_sub_objects
db = router.db_for_write(f.rel.through.__class__, instance=self)
File "/path/to//django/db/utils.py", line 134, in _route_db
chosen_db = method(model, **hints)
File "/path/to/my/app/routers.py", line 35, in db_for_write
object_name = model._meta.object_name
AttributeError: type object 'ModelBase' has no attribute '_meta'
>>>
On my project the error was raised in a different code path.
File "/home/harm/django12/django/core/management/commands/loaddata.py", line 174, in handle
obj.save(using = using)
File "/home/harm/django12/django/core/serializers/base.py", line 168, in save
setattr(self.object, accessor_name, object_list)
File "/home/harm/django12/django/db/models/fields/related.py", line 730, in __set__
manager.clear()
File "/home/harm/django12/django/db/models/fields/related.py", line 506, in clear
self._clear_items(self.source_field_name)
File "/home/harm/django12/django/db/models/fields/related.py", line 624, in _clear_items
db = router.db_for_write(self.through.__class__, instance = self.instance)
File "/home/harm/django12/django/db/utils.py", line 134, in _route_db
chosen_db = method(model, ** hints)
File "/home/harm/lascon/lascon/router.py", line 18, in db_for_write
if model._meta.app_label == 'exact'
and model._meta.object_name != 'ExactProfile':
AttributeError: type object 'ModelBase'
has no attribute '_meta'