I am making a Bookshop using Django-Oscar and everything is going great. but I want to add an app (model/view/admin) to show some information about the author of the book.
as i dont want to change any of the apps that exist. i just did a STARTAPP with a new name of my app AUTHORS. but django is showing me some mistakes. and i dont know if it is because i didnt fork Oscar, or why. in the examples that there are in the internet i havent found anything similar.
this is the error that i am getting when i am trying to do SYNCDB for my new app.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/reyesoscar/Desktop/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/reyesoscar/Desktop/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/reyesoscar/Desktop/oscar/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/reyesoscar/Desktop/oscar/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/reyesoscar/Desktop/oscar/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/reyesoscar/Desktop/oscar/frobshop/author/models.py", line 5, in <module>
class AuthorProfile(models.Model):
File "/Users/reyesoscar/Desktop/oscar/frobshop/author/models.py", line 6, in AuthorProfile
Author_name = models.ForeignKey(max_length=70, blank=False, null=True)
TypeError: __init__() takes at least 2 arguments (1 given)
thanks!!
When you use a ForeignKey you have to tell Django what model author_name is related to. Since its from another app it should look somehting like this.
author_name = models.ForeignKey('your_app_name.Modelname')
The app name is the other app you are taking the author from with the Model that the author is in.
https://docs.djangoproject.com/en/1.7/ref/models/fields/#foreignkey