python - Django create dynamic model -


i building web-page using python , django , mysql , have 5k tables identical in structure name different

example:

my_table_name_1 my_table_name_2 ... my_table_name_5000 

how can setup model have base template "my_table_name_" , when call controller want pass id , point right table

fyi: app in projects called 'polls'

in module.py used ./manage.py inspectdb > models.py. happens whenever add new table in db..i have of manual everytime. thats why want make dynamically..if add new table in db want able access without using ./manage.py inspectdb.

this polls/views.py

 class aboutdetail(detailview):     model = crawledtables     pk_url_kwarg = 'table_id'     template_name = 'polls/details.html'      def get_object(self):         if 'table_id' not in self.kwargs:             return crawledtables.objects.get(id=1)         else:             return crawledtables.objects.get(id=self.kwargs['table_id'])  def home(request):     return render(request, 'polls/base.html')   def tables(request):     tables = crawledtables.objects.order_by('id')     table_list = {'list_tables': tables}     return render(request, 'polls/tables.html', context=table_list)   class details(listview):     model = table1     template_name = 'polls/details.html'     context_object_name = 'list'     paginate_by = 15     queryset = table1.objects.all() 

crawledtable table names of tables crawled in db.

polls/urls.py

    urlpatterns = [         url(r'^$', views.home, name='home'),         url(r'^tables/$', views.tables, name='tables'),         url(r'^(?p<table_id>\d+)/details$', views.aboutdetail.as_view(), name='id_details'),         url(r'^(?p<table_id>\d+)/details$', views.details, name='details'),] 

this part of tables.html tells id number 4 or on whatever table id m selecting crawledtables

<td><pre><a href="{% url 'polls:details' list.id%}">{{ list.name }}</a></pre></td> 

so got display 1 table...and m trying display tables dynamically. happens now, if select 18th table crawled , want details on it, still show me the details of table1. because 'class details static'. , want change if select table100 want inside details of table100

updated: 5000 tables number. , when said structure identical meant structure same ( same columns) data inside tables complety different


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -