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, fie lds=('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'
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)
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)
I found the problem. There was another function named Post in the views
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.