NameError: name 'BookAdmin' is not defined - Django - python

I'm using Django and Python 3.6 I had this Error: NameError: name 'BookAdmin' is not defined and
this my code (models.py) in 'store' app.
from django.db import models
from django.utils import timezone
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=200)
description = models.TextField()
publish_date = models.DateField(default=timezone.now)
and in admin.py
from django.contrib import admin
from .models import Book
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author')
admin.site.register(Book, BookAdmin)
And the Error is
File "C:\venv\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\venv\lib\site-packages\django\apps\registry.py", line 115, in populate
app_config.ready()
File "C:\venv\lib\site-packages\django\contrib\admin\apps.py", line 23, in ready
self.module.autodiscover()
File "C:\venv\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\venv\lib\site-packages\django\utils\module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\venv\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\venv\bookstore\store\admin.py", line 5, in <module>
class BookAdmin(admin.ModelAdmin):
File "C:\venv\bookstore\store\admin.py", line 8, in BookAdmin
admin.site.register(Book, BookAdmin)
NameError: name 'BookAdmin' is not defined

class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author')
admin.site.register(Book, BookAdmin)
Register your admin outside of your class definition. Not inside it!
Or do this:
#admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author')

Related

AttributeError: module 'django.db.models.signals' has no attribute 'post_syncdb'

I created two models in my Django db. Now, I want to make migrations, but it shows error like this: AttributeError: module 'django.db.models.signals' has no attribute 'post_syncdb' . I tried to google the answer and found that this signal was deprecated in new Django version. It is not my project and I can't change the current version, so my colleagues recommended me to find the solution. What am I supposed to do if I can't change the version of Django and working on dev branch in project? How do I make migrations? What packages I can update?
My models:
class Categories(models.Model):
name = models.CharField(max_length=100)
position = models.IntegerField(unique=True)
def __str__(self):
return self.name
#classmethod
def get_default_pk(cls):
obj, created = cls.objects.get_or_create(
name='No category was added',
position=99
)
return obj.pk
class Shop(models.Model):
name = models.CharField(_('shop name'), max_length=128)
domain = models.CharField(_('domain'), max_length=128)
active = models.BooleanField(_('active'), default=True)
position = models.PositiveSmallIntegerField(_('position'), default=0)
category = models.ForeignKey(Categories, on_delete=models.CASCADE, related_name='related_name_category',
default=Categories.get_default_pk())
class Meta:
ordering = ('position', 'name')
verbose_name = _('shop')
verbose_name_plural = _('shops')
def __str__(self):
return self.name
The whole traceback after running python3 manage.py makemigrations:
Traceback (most recent call last):
File "/Users/ArtemBoss/GitHubRepos/pricemon/manage.py", line 22, in <module>
main()
File "/Users/ArtemBoss/GitHubRepos/pricemon/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/constance/models.py", line 30, in <module>
signals.post_syncdb.connect(create_perm, dispatch_uid="constance.create_perm")
AttributeError: module 'django.db.models.signals' has no attribute 'post_syncdb'
Make sure that no model in your project uses post_syncdb as if so, it will prevent you from running the migrations command.
Also why can't you use an appropriate version of Django?

AttributeError: 'tuple' object has no attribute 'model'. How to fix this error?

I'm new to Django. Please help me to solve this error. I'm not getting any solution. I tried many stackoverflow solutions and GitHub solutions but I'm not getting where the error is coming from.
urls.py
# from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from user_profile.views import UserProfileViewSet, CoursesViewSet
router = routers.DefaultRouter()
router.register(r'user', UserProfileViewSet)
router.register(r'courses', CoursesViewSet)
urlpatterns = [
path('', include(router.urls))
]
models.py
from django.db import models
# Creating user profile model.
class Courses(models.Model):
courses = models.CharField(max_length= 100, blank=True)
def __unicode__(self):
return self.courses
class UserProfile(models.Model):
user_id = models.AutoField(primary_key = True)
imgUrl = models.CharField()
user_name = models.CharField(max_length=100)
user_description = models.TextField()
university_college = models.CharField(max_length=100)
course = models.ForeignKey(Courses, blank=True, null=True, on_delete=models.CASCADE)
views.py
from django.shortcuts import render
from rest_framework import viewsets
from user_profile.models import Courses, UserProfile
from user_profile.serializers import UserProfileSerializer, CoursesSerializer
# Use these two when you'll create url of one class inside another class
# from rest_framework.decorators import action
# from rest_framework.response import Response
class UserProfileViewSet(viewsets.ModelViewSet):
queryset = UserProfile.objects.all(),
serializer_class = UserProfileSerializer
class CoursesViewSet(viewsets.ModelViewSet):
queryset = Courses.objects.all(),
serializer_class = CoursesSerializer
serializers.py
from rest_framework import serializers
from user_profile.models import Courses, UserProfile
class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
user_id = serializers.ReadOnlyField()
class Meta:
model = UserProfile
fields = '__all__'
class CoursesSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Courses
fields = '__all__'
Exception log
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
self.check(display_num_errors=True)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 475, in check
all_issues = checks.run_checks(
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
return check_method()
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 494, in check
for pattern in self.url_patterns:
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 715, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\resolvers.py", line 708, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "D:\Works\DjangoProjects\note_sharing_application_backend\note_sharing_application_backend\urls.py", line 23, in <module>
path('api/v1/', include('user_profile.urls')),
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\urls\conf.py", line 38, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "D:\Works\DjangoProjects\note_sharing_application_backend\user_profile\urls.py", line 7, in <module>
router.register(r'user', UserProfileViewSet)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\routers.py", line 54, in register
basename = self.get_default_basename(viewset)
File "C:\Users\tanmo\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\routers.py", line 141, in get_default_basename
return queryset.model._meta.object_name.lower()
AttributeError: 'tuple' object has no attribute 'model'
Here is the github link of the app - Django
I tried many stackoverflow solutions but I am not understanding from where the error is coming from...
Not sure but I think the issue is with extra commas in both the views, they make it act as a tuple, see it correctly so it should be:
class UserProfileViewSet(viewsets.ModelViewSet):
queryset = UserProfile.objects.all()
serializer_class = UserProfileSerializer
class CoursesViewSet(viewsets.ModelViewSet):
queryset = Courses.objects.all()
serializer_class = CoursesSerializer
Kindly remove them.
Also, in imgUrl field there must be max_length in UserProfile model.

Having a ModuleNotFoundError! in Django

i have this project where there is a Login app and there is a Homepage app. The project files look like this
login
homepage
models.py
login
settings.py
urls.py
usersignup
models.py
manage.py
Here is usersignup/models.py
'''
from django.db import models
class UserDetail(models.Model):
first_name = models.CharField(max_length=225)
middle_name = models.CharField(max_length=255, blank=True, null=True)
last_name = models.CharField(max_length=255)
email = models.EmailField()
def __str__(self):
return self.first_name
class WebDetail(UserDetail):
# user = models.OneToOneField(UserDetail, on_delete=models.CASCADE, primary_key=True,)
username = models.CharField(max_length=255)
password = models.CharField(max_length=255)
'''
and here is homepage/models.py
'''
from django.db import models
from login.usersignup.models import UserDetail
class UploadProfilePicture(models.Model):
caption = models.CharField(max_length=2000)
image = models.ImageField(upload_to='images/')
class Profile(models.Model):
user = models.ForeignKey(UserDetail, on_delete=models.CASCADE)
'''
and when i run
'''
python manage.py check
'''
i get this error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\user\Documents\McDonald\Login\venv\lib\site-packages\django\core\management\__init__.py", line 401,
in execute_from_command_line
utility.execute()
File "C:\Users\user\Documents\McDonald\Login\venv\lib\site-packages\django\core\management\__init__.py", line 377,
in execute
django.setup()
File "C:\Users\user\Documents\McDonald\Login\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\user\Documents\McDonald\Login\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\user\Documents\McDonald\Login\venv\lib\site-packages\django\apps\config.py", line 211, in import_mod
els
self.models_module = import_module(models_module_name)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_modul
e
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\user\Documents\McDonald\Login\login\homepage\models.py", line 2, in <module>
from login.usersignup.models import UserDetail
ModuleNotFoundError: No module named 'login.usersignup'
so, is there any way i could import the UserDetail class in the usersignup/models to the homepage/models?
Thanks for your contribution
Instead of using :
from login.usersignup.models import UserDetail
try using this :
from usersignup.models import UserDetail

importing models.py in my custom template filters file rise "django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet."

I'm tying to create template filter, which will take value and search it in my model
import django
django.setup()
tried this it didn't help
Here is my code
catalog_custom_tags.py
from catalog import models
from django import template, shortcuts
register = template.Library()
#register.filter(name='test')
def test(value):
item = shortcuts.get_object_or_404(models.Equipment, pk=value)
return item.name
models.py
from django.db import models
class EquipmentCategory(models.Model):
name = models.CharField(verbose_name="Name", max_length=30, unique=True)
category = models.CharField(verbose_name="Category", max_length=20, unique=True)
def __str__(self):
return self.name
class EquipmentSubCategory(models.Model):
name = models.CharField(verbose_name="Name", max_length=30, unique=True)
category = models.ForeignKey(EquipmentCategory, on_delete=models.CASCADE)
subcategory = models.CharField(verbose_name="Sub Category", max_length=20, unique=True)
def __str__(self):
return self.name
class Material(models.Model):
name = models.CharField(verbose_name="Name", max_length=30, unique=True)
material = models.CharField(verbose_name="Material", max_length=30, unique=True)
def __str__(self):
return self.name
class Equipment(models.Model):
name = models.CharField(verbose_name="Name", max_length=30)
# category = models.CharField(verbose_name="Category", max_length=20)
# subcategory = models.CharField(verbose_name="Sub Category", max_length=20)
category = models.ForeignKey(EquipmentCategory, on_delete=models.CASCADE)
subcategory = models.ForeignKey(EquipmentSubCategory, on_delete=models.CASCADE)
dimension_x = models.IntegerField(verbose_name="Dimensions X(cm)", default=0)
dimension_y = models.IntegerField(verbose_name="Dimensions Y(cm)", default=0)
dimension_z = models.IntegerField(verbose_name="Dimensions Z(cm)", default=0)
weight = models.FloatField(verbose_name="Weight(kg)", default=0)
qty = models.IntegerField(verbose_name="Quantity", default=0)
image = models.ImageField(verbose_name="Foto", blank=True, upload_to='fotos/', max_length=20)
accessories = models.TextField(verbose_name="accessories", blank=True)
material = models.ForeignKey(Material, on_delete=models.CASCADE)
# material = models.CharField(verbose_name="Material", max_length=20, null=True)
color = models.CharField(verbose_name="Color", max_length=20, null=True)
location = models.CharField(verbose_name="Location", blank=True, max_length=20)
description = models.TextField(verbose_name="Description", blank=True)
def __str__(self):
return self.name
And i get this error
File "C:\Users\mro\PycharmProjects\EuroWeb\catalog\templatetags\catalog_custom_tags.py", line 1, in <module>
from catalog import models
File "C:\Users\mro\PycharmProjects\EuroWeb\catalog\models.py", line 4, in <module>
class EquipmentCategory(models.Model):
and Apps not loaded error
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\apps\registry.py", line 135, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Full traceback
Traceback (most recent call last):
File "C:/Users/mro/PycharmProjects/EuroWeb/manage.py", line 21, in <module>
main()
File "C:/Users/mro/PycharmProjects/EuroWeb/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\core\management\__init__.py", line 325, in execute
settings.INSTALLED_APPS
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
self._setup(name)
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\conf\__init__.py", line 66, in _setup
self._wrapped = Settings(settings_module)
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\conf\__init__.py", line 157, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\mro\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\mro\PycharmProjects\EuroWeb\EuroWeb\settings.py", line 140, in <module>
django.setup()
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\mro\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\mro\PycharmProjects\EuroWeb\catalog\templatetags\catalog_custom_tags.py", line 1, in <module>
from catalog import models
File "C:\Users\mro\PycharmProjects\EuroWeb\catalog\models.py", line 4, in <module>
class EquipmentCategory(models.Model):
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\db\models\base.py", line 103, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\apps\registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\mro\PycharmProjects\EuroWeb\venv\lib\site-packages\django\apps\registry.py", line 135, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
The file structure should be something like this.
polls/
__init__.py
models.py
templatetags/
__init__.py
poll_extras.py
views.py
and in template
{% load poll_extras %}
https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/#code-layout
ok... i found a solution. I appreciate if some one can tell me why this happens...
the solution is:
to put filter which cause this error into another file

Django model invalid meta syntax

In my model class i am adding meta class for detail regarding detail but after running
python manage.py makemigrations it is showing error
my model class is
from django.db import models
# Create your models here.
class Category(models.Model):
"""Category model."""
title = models.CharField( max_length=100)
slug = models.SlugField(_(unique=True)
class Meta:
verbose_name = 'category'
verbose_name_plural = 'categories'
db_table = 'blog_categories'
ordering = ('title',)
def __str__(self):
return u'%s' % self.title
#permalink
def get_absolute_url(self):
return ('blog_category_detail', None, {'slug': self.slug})
class Post(models.Model):
"""Post model."""
STATUS_CHOICES = (
(1, 'Draft'),
(2, 'Public'),
)
title = models.CharField( max_length=200)
slug = models.SlugField(unique_for_date='publish')
author = models.ForeignKey(User, blank=True, null=True)
body = models.TextField( )
tease = models.TextField(blank=True, help_text=_('Concise text suggested. Does not appear in RSS feed.'))
status = models.IntegerField( choices=STATUS_CHOICES, default=2)
allow_comments = models.BooleanField( default=True)
publish = models.DateTimeField( default=datetime.datetime.now)
created = models.DateTimeField( auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
categories = models.ManyToManyField(Category, blank=True)
tags = TagField()
objects = PublicManager()
class Meta:
verbose_name = 'post'
verbose_name_plural ='posts'
db_table = 'blog_posts'
ordering = ('-publish',)
get_latest_by = 'publish'
def __str__(self):
return u'%s' % self.title
#permalink
def get_absolute_url(self):
return ('blog_detail', None, {
'year': self.publish.year,
'month': self.publish.strftime('%b').lower(),
'day': self.publish.day,
'slug': self.slug
})
def get_previous_post(self):
return self.get_previous_by_publish(status__gte=2)
def get_next_post(self):
return self.get_next_by_publish(status__gte=2)
class BlogRoll(models.Model):
"""Other blogs you follow."""
name = models.CharField(max_length=100)
url = models.URLField()
sort_order = models.PositiveIntegerField(default=0)
class Meta:
ordering = ('sort_order', 'name',)
verbose_name = 'blog roll'
verbose_name_plural = 'blog roll'
def __str__(self):
return self.name
def get_absolute_url(self):
return self.url
and the error is followed:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/core/management/__init__.py", line 325, in execute
django.setup()
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1572, in get_code
File "<frozen importlib._bootstrap>", line 1532, in source_to_code
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/vivekpradhan/finalbasket/basket/blog/blogger/models.py", line 9
class Meta:
^
SyntaxError: invalid syntax
(basket)vivekpradhan#vivekpradhan-AOD270:~/finalbasket/basket/blog$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/core/management/__init__.py", line 325, in execute
django.setup()
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/home/vivekpradhan/finalbasket/basket/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1467, in exec_module
File "<frozen importlib._bootstrap>", line 1572, in get_code
File "<frozen importlib._bootstrap>", line 1532, in source_to_code
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/vivekpradhan/finalbasket/basket/blog/blogger/models.py", line 9
class Meta:
^
SyntaxError: invalid syntax
you lost a ")" at slug = models.SlugField(_(unique=True)
You should pylint your code before you ask things like this.

Categories

Resources