Reputation: 39
I have a separate Django app for two different cities. I have models of the same name, for each of those cities, and would like to bring them into the same view. When i import the models of both apps, the data doesnt render, i assume because Django doesnt know which one to use. When I import just corpus_christi, the template renders the data just fine, and vice versa. How can I specify from which app i want to bring these models?
Here is my view
from django.shortcuts import render
from django.http import HttpResponse
from corpus_christi.models import Service, Member
from lake_charles.models import Service, Member
def index(request):
return render(request, 'pages/index.html')
def corpuschristi(request):
residential = Service.objects.filter(service_type="Residential")
commercial = Service.objects.filter(service_type="Commercial")
prelisting = Service.objects.filter(service_type="Pre Listing")
members = Member.objects.all()
context = {
'members': members,
'residential': residential,
'commercial': commercial,
'prelisting': prelisting
}
return render(request, 'pages/corpuschristi.html', context)
def lakecharles(request):
return render(request, 'pages/lakecharles.html')
Upvotes: 0
Views: 226
Reputation: 356
You could try something like this:
from corpus_christi.models import Service as corpus_service
from corpus_christi.models import Member as corpus_member
from lake_charles.models import Service as lake_service
from lake_charles.models import member as lake_member
And then call them as needed.
Upvotes: 2