Hi Team,

django admin page has inline model.


models.py

-------------


class Details(models.Model):
    url = models.CharField(max_length=250)
    description = models.TextField()
    created_at = models.DateField(auto_now_add=True)
    updated_at = models.DateField(auto_now=True)



class Mapping(models.Model):
    utr = models.ForeignKey(Details)
    code = models.CharField(max_length=200)
    year = models.ForeignKey(Year)
    schedule = models.ForeignKey(Page)
    field_type = models.CharField(choices=TYPE_CHOICE, max_length=200)
    income = models.ForeignKey(Income, blank=True, null=True)
    expense = models.ForeignKey(Expense, blank=True, null=True)
    fields = models.ForeignKey(Field)


admin.py

------------

class MappingInline(admin.TabularInline):
    class Media:
        js = (settings.MEDIA_URL + 'js/st-api.js',
           settings.MEDIA_URL + 'js/vendor/jquery.js')

    model=Mapping
    extra=0

admin.site.register(Details, inlines=[MappingInline])
admin.site.register(Mapping, MappingAdmin)



=> using st-api.js, i have written ajax calls to filter the foreign fields 
based on the other fields input.


On selecting year, I have filtered the schedule based on year.

On selecting Schedule, I have filtered the Income based on Schedule.

Like wise I have filtered other fields(Income, expense, fields)


On saving on admin page I am able to save the entries and same entries are 
rendered back when page gets refreshed.


But, the filtered values are not available in the drop downs. Instead dropdowns 
are showing all the choices.


Please help me out so that, after saving the entries, after page get refreshed, 
I need filtered dropdown list so that, we can update the dropdown list.(Ex : 
selected year, based on year schedule dropdown has filtered.  I have selected 
one schedule and saved. Now page rendered back showing the selected schedule of 
that particular year. Now I need to select other schedule of the same year.)


Thanks in advance.




Regards,


Teja Y

LAMP





________________________________
From: [email protected] <[email protected]> on behalf 
of Mark Phillips <[email protected]>
Sent: Saturday, June 30, 2018 3:49:15 AM
To: django users
Subject: Re: Django Admin

Teja,

First, let me suggest you just copy and paste your models from models.py. 
People who use Django a lot may find it easier to read the code (because they 
are familiar with the syntax and layout) than your typed summary of the classes.

Second, Django by itself cannot do what you want it to do. Django just makes 
html pages from the models, views, and templates you define, or are found in 
the admin classes. Once a page is displayed, that is what you get until the 
page is re-loaded from the server. What you are trying to do is have the page 
change without a round trip to the server. For that, you need some form of 
Javascript talking to the server as well. You can change the contents of an 
html page based on a selection in a select box using some Javascript to detect 
the change in the page and then talks to a Django view; the view in Django gets 
the data you want from the database and returns that data to the script, which 
updates the html page; and an appropriate url for the script to talk to the 
view and for the view to listen to. That is just one way to accomplish what you 
want to do. There are also add-on django projectst that will do this for you. 
Google for django smart selects, django autocomplete, django ajax, and this 
page of projects - https://djangopackages.org/grids/g/auto-complete/.

Good luck!

Mark

On Fri, Jun 29, 2018 at 7:27 AM, Teja Yerraballe 
<[email protected]<mailto:[email protected]>> wrote:

Hi Team,


I have created 4 models ( class Company, class Department, class Section, class 
Employee )


Company Model has : CMP1, CMP2, CMP3, CMP4, CMP5(Year is the foreign key in 
this model)


Department Model has : DEP1, DEP2,DEP3,DEP4,DEP5 (Company is the foreign key in 
this model)


Section Model has : SEC1, SEC2,SEC3,SEC4,SEC5 (Department is the foreign key in 
this model)


Employee Model has : EMP1,EMP2,EMP3,EMP4,EMP5 (Section is the foreign key in 
this model)



Now I have created 2 more models (class Details, Class Map)


Details Model Fields:


salary


Map Model Fields :


Company ( foreign key Company Model)

Department (foreign key Department Model )

Section (foreign key section Model)

Employee (foreign key employee Model)


Details Model will Map salary for the employees


I need to show these two models in admin page ( class Map as the inline model 
for class Details)


=================================================================================

ADMIN PAGE looks as below :


Details


select salary range

 (drop down)


MAP [ inline Model ] : Need to Map employees who come under the salary range


  1.   select Company      select Department        select Section       select 
Employee

           (drop down)              (drop down)                   (drop down)   
        (drop down)

     2. select Company      select Department        select Section       
select Employee

           (drop down)              (drop down)                   (drop down)   
        (drop down)

     3. select Company      select Department        select Section       
select Employee

           (drop down)              (drop down)                   (drop down)   
        (drop down)


======================================================================================


=> On selecting a company, we should display only departments in that company.

=> On selecting Department, we should display only sections in that Department.

=> On selecting Section, we should display only employees in that Section.




I am messed with this implementation, Please help me out in this. If possible 
please brief me the steps to follow on this implementation


Thanks in Advance


Regards,


Teja Y

LAMP





[Aspire Systems]

This e-mail message and any attachments are for the sole use of the intended 
recipient(s) and may contain proprietary, confidential, trade secret or 
privileged information. Any unauthorized review, use, disclosure or 
distribution is prohibited and may be a violation of law. If you are not the 
intended recipient, please contact the sender by reply e-mail and destroy all 
copies of the original message.

--
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 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/SG2PR02MB3532FF8BEF86B8796A035268FF4E0%40SG2PR02MB3532.apcprd02.prod.outlook.com<https://groups.google.com/d/msgid/django-users/SG2PR02MB3532FF8BEF86B8796A035268FF4E0%40SG2PR02MB3532.apcprd02.prod.outlook.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
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 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2MedgiOTf6uExRKEVzyLNcMU1q_xjCWAw79sr-bDyZo9Q%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CAEqej2MedgiOTf6uExRKEVzyLNcMU1q_xjCWAw79sr-bDyZo9Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
[Aspire Systems]

This e-mail message and any attachments are for the sole use of the intended 
recipient(s) and may contain proprietary, confidential, trade secret or 
privileged information. Any unauthorized review, use, disclosure or 
distribution is prohibited and may be a violation of law. If you are not the 
intended recipient, please contact the sender by reply e-mail and destroy all 
copies of the original message.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/TY2PR02MB353649902EC546994FA7943AFF400%40TY2PR02MB3536.apcprd02.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to