python - Filtering by Foreign Key in Django -


We have enhanced the Django user model with our company record model. Each company record is a user with all the profiles when that user is on the login system, so we can pull data into company records.

Our campaign model deals with our company with another company. Thus, each company has several campaigns in the record. I want to take those campaigns related to company records. Basically, a company is a registered user. There are several campaigns of a company record when a company Richter is logged in for a user system, so I want to get it from affiliate campaigns.
Keeping in mind, I want to take all the campaigns and filter them, only our users related campaigns will be shown.

  Required parts of our company # models.py class CompanyRecord (models.Model): user = models.OneToOneField (user) company_id = models.IntegerField (primary_key = true) company_name = model. CharField (MAX_LENGTH = 100) class campaign (models.Model): CAMPAIGN_ID = models.IntegerField (primary_key = true) company_id = models.ForeignKey (CompanyRecord) category_id = models.ManyToManyField (category) campaign_title = models.CharField (MAX_LENGTH = 100) And view.py@login_required DEF kampanyalar (part of the request): if request.user.is_authenticated does not return (): return HttpResponseRedirect ('/ login /') company = request.user.get_profile userscampaig N = Campaign.objects. Filter (### problem ###) content = {'Kampanyalar': kampanyalar, 'company': company} return render_to_response ('kampanyalar.html', content, context_instance = RequestContext (request))  

Get all campaigns s for companyRecord relationship behind and using company.campaign_set :

  company = request.user.get_profile () userscampaign = company.campaign_set.all ()  

Also see:


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -