python - Translating SQL request to django -


I am trying to create a request (in a digenfo) that will return an array of posts (only the user's rank, Post User:

Post:

  Class Post (Model.Model): Title = Model.carfield ("Headline", Maximum_length = 100) body = Model . TextField (Max_length = 1000) user_id = models.ForeignKey (user) thumbnail = models.FileField (upload_to = get_upload_file_name, empty = true) timestamp = model. DataTamField (auto_now_add = true)   

The following / followers:

  class.model: who_id = models.IntegerField () whom_id = models IntegerField () Timestamp = models.DateTimeField (auto_now_add = True)   

User: Prefix User, exclusive = true) profile_pic = models.FileField (upload_to = get_upload_file_u_name, default = 'website model = model.ccarfield (empty = true, max_length = 100) location = model.chhfield (empty = true, max_long = 100) def __unicode __ (default = true =) Auto): "% s profile"% self.user

return the SQL request I created:

  from SELECT * POSTS where user_id IN (Where user_id = 1),   

select whom_id from FOLLOWERS) So, I tried to translate this SQL code as a dynamic language but I was not able to have the main problem That i can not request for an array

Need help! Thanks

try it

  Post.objects.filter (user_id__in = FollowUser.objects.filter (who_id = 1) .values_list ('whom_id'))   

You can assign it to your views.py in request Parameter

  Post.objects.filter (user_id__in = FollowUser.objects.filter (who_id = request.user.id) .values_list ('whom_id'))    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -