So im trying to use my django installation to create a dashboard a combination of all the data from the 4 other models and views. For our use of django we mainly use it for stats so it's generally just pulling numbers out onto the main index page. Right now I have my index template set up as a redirect_to_template and it goes straight to a template (since everything is still static). Im trying to figure out if im going to have to create another app and pull in all the data to a new view & model for this dashboard page, or if I should create sub-templates if that would work to pull the data.
Thanks again!
I think you're better of with pulling the data by using ajax from your dashboard, it will be a better UX when you have a lot of data to fetch. For that you can use one of the known 3rd party apps for creating REST API or change your existing views to deliver json response as well.
To help anyone that has the question in the future. I ended up importing the apps such as
from status import Alert
context['list'] = Alert.objects.filter(All My Filters Here! (link below))[:8]
Then just for loop list in the template!
https://docs.djangoproject.com/en/dev/ref/models/querysets/
Hope this is helpful to someone else!
Related
I'm new to django and still trying to figure out logic. I watched a bunch of videos and I know how to create those examples but I'm not quite there. I'll explain what I want and maybe someone can explain to me a logic how to do, yes?
I created an app and inside an app I connected urls, settings, html and I have working site. Now I want to input data in django website, django to pass data to xlsxwriter script to create xlsx document, and to pass that document to user to download.
My logic: What I need now, is to create some kind forms (but not for registered users, it can use anyone who uses a website) to input data. Which forms are best? Than I need to pass () that data to function that are in views that will get an arguments from html page through some kind of forms, create document, and pass that to download button.
I have database created by django, but I can't print a text in my page from database. What function I will learn to make that.
You should have elaborated your question with your code samples. Before diving deep into any framework, you should go with tutorials. Django website itself provides you a step by step tutorial for that.
Here are few references:
https://www.youtube.com/watch?v=MEcXbeY4_DQ
https://docs.djangoproject.com/en/1.11/intro/tutorial01/
You will need to read the database in respective view function called in views.py in your app; and return the data as context to template so that you will be able to access them and print them.
I am a php programmer, I have built some REST based solutions in php. Now I am learning python/django. I want to make a REST based solution in Django ( only for knowledge purpose ). I do not want to use any of REST frameworks/toolkits as This project is more a exploring django/python say how they work with raw REST concept.
I searched on net, But examples/tutorial filled on already built solutions. I also checkout for request method based filtering. I am thinking of two approaches.
Either urls.py have way to check request method and transfer to respective method in views.py.
Or I can add a pre load hook/class which determine request method on application initialize, And called respective method so overriding urls.py behavior (my preferred method).
If anybody can suggest a django way to do this?
Update : I found some interesting comments on SO, like https://stackoverflow.com/a/20898410/1230744 AND https://stackoverflow.com/a/1732520/1230744. Need to check if they can have the solution, I am searching.
Well I get the answer of my questions finally from following link. It is possible through using Class based Views + serialization.
Restful routes and Django
Snippet links in side above link gave pretty much example to gave quite picture of how one can create a REST Api using only Django Core. Also I used serialize https://docs.djangoproject.com/en/dev/topics/serialization/ for Json encoding
( Now if anybody prefer, he can flag duplicate the question. ;) )
You can start from learning the code of this projects:
http://tastypieapi.org/ Tastypie
http://www.django-rest-framework.org/ Django REST framework
They are snadrd de facto for REST API for Django and their code could be a good starting point.
Also, please review this questions:
Creating a REST API for a Django application
Adding REST to Django
Django and Restful APIs
I have been trying to get my head around Django over the last week or two. Its slowly starting to make some sense and I am really liking it.
My goal is to replace a fairly messy excel spreadsheet with a database and frontend for my users. This would involve pulling the data out of a table, presenting it in a web tabular format, and allowing changes to be made through text fields and drop down menus, with a simple update button that will update all changes to the DB.
My question is, will the built in Django Forms functionality be the best solution? Or would I create some sort of for loop for my objects and wrap them around html form syntax in my template? I'm just not too sure how to approach the solution.
Apologies if this seems like an simple question, I just feel like there is maybe a few ways to do it but maybe there is one perfect way.
Thanks
The fastest way not to implement you own pages and to have a tabular view of your data is to use the django's built-in admin interface. It gives you sorting, filtering and search functionality and quick to start. You just need to define your models in models.py and setup the admin pages as described in the docs.
Normally the admin page is not used as a representation to users or customers but in the case you described it seems a clean and quick choice.
Exporting the excel sheet in Django and have the them rendered as text fields , is not as easy as 2 step process.
you need to know how Django works.
First you need to export the data in mysql in database using either some language or some ready made tools.
Then you need to make a Model for that table and then you can use Django admin to edit them
I'm currently playing with django to get acquainted with it. I want to build a litte cms by myself. In an apps model i define a string database-field which represents the url, a field for the bodytext etc. Now i wonder what would be the best way to integrate the url and its corresponding content from the set of data.
Do I have to use views.py for sending database-fields with url data to urls.py?
Is it better to process a database query within urls.py to get the urls?
I hope you can follow me...
Thanks a lot
I've read this question several times and I'm still not sure exactly what you're asking.
The tutorial tells you exactly how to resolve addresses to db entries: capture the components of the URL in your urlconf, pass them to the view, and query your models in the view dependent on the parameters passed from the URL. If this doesn't answer your question, you'll need to explain further what's puzzling you.