Open alsiPanda opened 3 years ago
@lifenautjoe any way you could help us sort this out ??
@lifenautjoe anyone else whom you know could help us figure this out ?
@lifenautjoe, after various trials and errors, and plenty of google search, the main issue seems to be with generic relations. For some reason, whenever the topposts contain a post without image and video, the content_object in PostMediaSerializer
throws an Invalid model error. I have tried adding read_only=True
to the GenericRelatedField, but to no avail. Anyway to go about solving this issue ?
I have changed the post in PostImage to ForeignKey from one-to-one. And added a CharField called ptype, which I wanted to use for filtering based on its value. In getTopPosts, I have moved post__image from
select_related
toprefetch_related
, and added ptype toonly
. I have also added ptype to curate_top_posts in jobs. On other hand, I have also addedmany=true
wherever PostMediaSerializer is used.I then added a query in top_post_community_query, postptypeexact="string" where string is recieved from request in view. Made relevant changes to serializer as well. This is where I am facing the problem of bad request 400 in api, and invalid model in app. If I comment out the ptype query, error dissapears and I get a list of top posts. But if I keep the query and instead comment out
content_object
in PostMediaSerializer, then also the 400 error dissapears, although I get error in app due to no Content object.I tried to add the ptype field to TopPost model instead, so I could use it direct, and made all the relevant changes to jobs, and ran migration successfully. But then the scheduled job fails with
Integrity error, 1364, ptype has no default
even though I have added default string in the ptype field. I also tried to set null=True and null=False, but getting the same error in the failed job.