Tags down


Django Admin filter on Foreign Key property

By : user3851563
Date : October 16 2020, 11:12 AM
seems to work fine See https://code.djangoproject.com/ticket/3400 . It works ok in django 1.3 :)
code :

Share : facebook icon twitter icon

Is it possible to filter choices on a foreign key in Django Admin panel?

By : user3104678
Date : March 29 2020, 07:55 AM
Hope that helps You could write such a filter with AJAX (using jQuery or a similar framework would be the easiest way to do so). You'd create a custom form widget with two lists. The first would be populated with all available programs by the server when the page is loaded. Your javascript would then wait for a selection to be made, and then ask the server (thats the AJAX part) for a list of the courses in that program, and update the second list accordingly.
However, for your situation I would say that is overkill; it would be far easier to do as jammon's answer says and put the admin for the Grade model within the corresponding Course admin (this is known as an inlined model admin; see the Django documentation on the subject). Unfortunately the example code given in their answer doesn't work, so I've created the following example which works for me.
code :
from django.contrib import admin
from myapp.models import Program, Course, Grade

class GradeInline(admin.TabularInline):
    model = Grade
    extra = 1
class CourseAdmin(admin.ModelAdmin):
    model = Course
    inlines = (GradeInline,)
from django.contrib import admin
from myapp.models import Program, Course, Grade

class GradeInline(admin.TabularInline):
    model = Grade
    extra = 1

class CourseAdmin(admin.ModelAdmin):
    model = Course
    inlines = (GradeInline,)

admin.site.register(Course, CourseAdmin)

How to filter a django query set by a foreign key field, in django admin?

By : Jon Hanshew
Date : March 29 2020, 07:55 AM
like below fixes the issue CHAR_LENGTH(code__code_key) is SQL. It doesn't know about the code__ prefix.
One possible solution is:
code :
code_regs = CodeRegistry.objects.filter(
                 .extra(where=['CHAR_LENGTH(code_key) = 10']))

Django admin filter fields on foreign key

By : aswin moorthi
Date : March 29 2020, 07:55 AM
With these it helps You'll want to get the Account from the user context, which you can then filter on:
code :
account = Account.objects.get(user_id=request.user.id)

return qs.filter(school_id=account.school_id)

Django Admin filter by function / filter only by first object in reverse foreign key lookup

By : André Mendonça
Date : March 29 2020, 07:55 AM
To fix the issue you can do As you've discovered it isn't trivial to filter in that manner. If you are accessing that information regularly it is probably also not very efficient either.
I would suggest that you store a reference to the latest tracking event in the Tracking model itself:
code :
class Tracking(models.Model)
    # ...
    last_event = models.ForeignKey(TrackingEvent, null=True)
from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=TrackingEvent)
def update_latest_tracking_event(sender, instance, created, **kwargs):
    # Is this a new event?
    if created:
        # If yes, then update the Tracking reference
        tracking = instance.tracking
        tracking.last_event = instance
# I'm just guess what event types you have...
cancellation = TrackingEventType.objects.get(name='cancel')

How do I filter the foreign keys in the django admin?

By : Tha Oldswingz
Date : March 29 2020, 07:55 AM
around this issue You will have to use JavaScript for this purpose. Best is probably to use a module such as django-autocomplete-light in combination with select2.
Then you will be able to filter results based on the value of other fields in the form.
Related Posts Related Posts :
  • Avoiding unnecessary slice copying in Python
  • Outlook contacts using Python client
  • ctypes loading a c shared library that has dependencies
  • Where should sys.path.append('...') statement go?
  • How to set target hosts in Fabric file
  • MATLAB to Python Code conversion (NumPy, SciPy, MatplotLib?)
  • Feedparser-basics how to
  • In Python with sqlite is it necessary to close a cursor?
  • libxml2 install error: command 'gcc' failed with exit status 1? What are the dependencies of libxml2?
  • customize the django admin panel?
  • How to decode JSON with Python
  • Modify excel file in python on linux enviroment
  • Jython image manipulation
  • Python Drawing Portion of Image When Mouse Hover
  • How do I make a command line program that takes arguments?
  • Python and NGREP
  • How can I make URLs in Django similar to stackoverflow?
  • how to make python to return floating point?
  • how are pgp keys formatted?
  • Why does += behave unexpectedly on lists?
  • memory location of dictionary in python 2.6.4 only?
  • Accessing a ServerFactory from the Service in Twisted
  • Scraping for a "preview" of a webpage - Python
  • Installing PIL on Snow Leopard
  • App Engine (Python) Datastore Precall API Hooks
  • python switch by class name?
  • Running Python With STDIN From Bash
  • Automate Windows GUI operations with Python
  • Concurrent downloads - Python
  • Python directory list returned to Django template
  • Google App Engine with Eclipse?
  • Can't import numpy into embedded ironpython engine
  • Secure Python Markdown Library
  • How can I implement a tree in Python?
  • How to get parameters of fail case in Python unittest?
  • How to make a count in python so that the program ends after a particular number of counts?
  • How can I create an ODBC connection to SAS?
  • Creating a global function, accessible from all classes, with Python + Pylons
  • How can I access a function from FORTRAN which is writen in Python?
  • How can i capture the UDP packet and find the TTL Values from the packet using python
  • Match start and end of file in python with regex
  • How to switch axes in matplotlib?
  • django error :1146, "Table 'basic_project.topics_topic' doesn't exist"
  • Python and Memory Consumption
  • Can you go to a line with the file operations in python?
  • Python Boto S3 to work with Custom Domains in Amazon S3
  • Where can i get exercises for 'Dive into Python'?
  • merging Python dictionaries
  • Urlretrieve and User-Agent? - Python
  • pyxmpp: quick tutorial for creating a muc client?
  • append new row to old csv file python
  • Teaching Python to a Law Student
  • How do I drop a bash shell from within Python?
  • Simulation of molecular dynamics in Python
  • mod_wsgi excessively slow at startup?
  • How to convert from unicode with python
  • In Django, how do I make my sessions persist through http://mydomain.com and http://www.mydomain.com?
  • Is there a way to create a python object that will be not sortable?
  • Listing names of available Virtualbox VMs using Python
  • Regex redefinition error
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org