select records from a model in another django app

17 views
Skip to first unread message

Perceval Maturure

unread,
Jul 30, 2019, 6:59:55 AM7/30/19
to Django users
i want to display  model data using a class based view from another model in a different app.any idead

Nitin Kumar

unread,
Jul 30, 2019, 7:33:19 AM7/30/19
to django...@googlegroups.com
Import another app model. 

On Tue, 30 Jul, 2019, 4:28 PM Perceval Maturure, <drper...@gmail.com> wrote:
i want to display  model data using a class based view from another model in a different app.any idead

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5529da22-0981-43ca-a98a-d13edcc5ba94%40googlegroups.com.

John Bagiliko

unread,
Jul 30, 2019, 7:53:46 AM7/30/19
to django...@googlegroups.com
Import the model from the app of choice and use it as usual.

John Bagiliko

unread,
Jul 30, 2019, 7:54:57 AM7/30/19
to django...@googlegroups.com
I stand to be corrected

Perceval Maturure

unread,
Jul 30, 2019, 2:58:55 PM7/30/19
to django...@googlegroups.com
thanks for the response just to be more elaborative, here is my import code and view code. same code is working in the archivesuploads app but when i try to fetch the queryset in the other app it does not return records

#import code
from django.shortcuts import render
from django.shortcuts import render, redirect
from .models import StaffDetail, PeopleDetail, StudentDetail
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.urls import reverse
from django.utils import timezone # to display date and time as per timezone
from django.views.generic import ListView, DetailView, View, TemplateView
from archivesuploads.models import Archivesuploads, Archivetypes, Interests

#view
class ArchivesuploadsListView(ListView):

    context_object_name = 'object_list'
    queryset = Archivesuploads.objects.all()#[:2] add this to limit the number of publications
    template_name = "person.html"



--
Perceval Maturure
083 303 9423

Marius Räsener

unread,
Jul 30, 2019, 5:58:44 PM7/30/19
to Django users
Hey Perceval,

it seems like you have way too many import statements.

something like this should be enough:

from django.views.generic import ListView
from .models import StaffDetail, PeopleDetail, StudentDetail

class ArchivesuploadsListView(ListView):
    queryset = Archivesuploads.objects.all()#[:2] add this to limit the number of publications  # <- optional
    template_name = "person.html" # <- optional

    model = StaffDetail # <-not optional

if you want to use a model from a different app, you need to import only this specific model:

from otherapp.models import OtherModel

and then just tell the ListView with model = OtherModel you want to use it.

hope it helps

p.s.: please use a different Font! :)
Import another app model. 

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Perceval Maturure

unread,
Jul 31, 2019, 4:44:45 AM7/31/19
to django...@googlegroups.com
Hi Marius
thanks for your input,i did remove the import statements but nothing returned on my template surprisingly in another app the code is working.

#view
from django.shortcuts import render

from django.views.generic import ListView, DetailView, View, TemplateView
from archivesuploads.models import Archivesuploads, Archivetypes, Interests
from .models import StaffDetail, PeopleDetail, StudentDetail


class ArchivesuploadsListView(ListView):
    #model = Archivesuploads

    context_object_name = 'object_list'
    queryset = Archivesuploads.objects.all()#[:2] add this to limit the number of publications
    template_name = "person.html"



#template
  {% if object_list %}
      <ul>
        {% for archiveupload in object_list %}
        <p>{{ archiveupload.name }}
          <a style="color:#99241B;" href="{{ archiveupload.url }}" target="_blank"> <i>{{ archiveupload.title }}</a></i>
          <b>({{ archiveupload.publication_date | date:"Y"}})</b>
          {{ archiveupload.general_doi }}</p>
        {% endfor %}
      </ul>

      {% else %}
      <p>There are no Publications</p>
      {% endif %}

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1a6af686-3708-4de9-86d8-d106400881ff%40googlegroups.com.

Marius Räsener

unread,
Jul 31, 2019, 5:07:36 AM7/31/19
to Django users
This can have several causes - f.e. did you add the ListView to your urls.py? is the import of the models working? (this implies to check your folder/module structure)

Perceval Maturure

unread,
Jul 31, 2019, 5:35:27 AM7/31/19
to django...@googlegroups.com
Hi Marius
image.png

below is my urls.py for the peoplemanager app, my Archivesuploads ListView is in peoplemanager app and not archiveuploads, can i then change the import 

from  archivesuploads.views import ArchivesuploadsListView to peoplemanager.views import ArchivesuploadsListView


To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b0e22c37-4b2c-48c4-bae5-5afd14149359%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages