Wednesday, July 31, 2019

Re: select records from a model in another django app

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)

Am Mittwoch, 31. Juli 2019 10:44:45 UTC+2 schrieb Perceval Maturure:
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 %}

On Tue, Jul 30, 2019 at 11:59 PM Marius Räsener <m...@mehr-handwerk.de> wrote:
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! :)

Am Dienstag, 30. Juli 2019 20:58:55 UTC+2 schrieb Perceval Maturure:
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"

On Tue, Jul 30, 2019 at 1:54 PM John Bagiliko <john.b...@aims-senegal.org> wrote:
I stand to be corrected

On Tue, Jul 30, 2019, 11:53 AM John Bagiliko <john.b...@aims-senegal.org> wrote:
Import the model from the app of choice and use it as usual.

On Tue, Jul 30, 2019, 11:32 AM Nitin Kumar <nitink...@gmail.com> wrote:
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...@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.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKzNicG9paZfyTWFqMD5hNxwrhT-FH1rKFqxA24oj%3DMprzQZtw%40mail.gmail.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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAC26BE218VXdczBfrQD4_CWEf-PyTUML-DgjBoTwdH%3DSmAaNkA%40mail.gmail.com.


--
Perceval Maturure
083 303 9423

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1a6af686-3708-4de9-86d8-d106400881ff%40googlegroups.com.


--
Perceval Maturure
083 303 9423

--
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+unsubscribe@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.

No comments:

Post a Comment