0
votes

I'm trying to create a form that submits a model with a foreign key but i got this error :

Traceback (most recent call last): File "C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 41, in inner response = get_response(request) File "C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view return view_func(*args, **kwargs) File "~.py", line 21, in wrap return function(request, *args, **kwargs) File "~.py", line 32, in wrap return function(request, *args, **kwargs) File "~.py", line 428, in example PostFormSet = inlineformset_factory(User, Post, fields=('longitude', 'latitude', 'placename', 'explanation', )) File "C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\forms\models.py", line 1038, in inlineformset_factory fk = _get_foreign_key(parent_model, model, fk_name=fk_name) File "C:\Users\~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\forms\models.py", line 980, in _get_foreign_key opts = model._meta AttributeError: 'function' object has no attribute '_meta'

model.py

class Post(models.Model):
      owner = models.ForeignKey(User,on_delete=models.CASCADE,related_name="posts",blank=False,null=False)
      </other fields>...

class PostImage(models.Model):
      owner = models.ForeignKey(Post,on_delete=models.CASCADE,related_name="images",blank=False,null=False)

views.py

def example(request):
    context = {
        'hellow we':"qfqf"
    }
    print(request.user)
    PostFormSet = inlineformset_factory(User, Post, fields=('longitude', 'latitude', 'placename', 'explanation', ))
    print("------------------------------------------------------------")
    print(frm.errors)
    return JsonResponse(context, encoder=JSONEncoder)   
1
Looks like either User or Post is a function, not a model.Kevin Christopher Henry

1 Answers

0
votes

I found the problem. There was another function named Post in the views