How can I integrate autogenerated database model diagrams into admin documentation interface? - django

I'm using graph_models from django-extensions to generate diagrams from a Django application's database models. I would like to integrate the diagram into the documentation of the admin interface (django.contrib.admindocs). Is there a way to integrate the diagrams (preferably by executing a streamline command comparable to python manage.py collectstatic)?

I don't see why you can't. One potential way would be to create a management command that invokes the graph_models command with parameters such that the files are output into the STATIC_FILES directory (it might be the other static file setting).
Then you can override whichever admin template you'd like to have the diagrams shown on. Perhaps including a link to the image of the diagram per table? I think that'd be django/contrib/admin/templates/admin/index.html.
You'd need to define some naming convention that would be used in your management command as well as in the overriding admin template such that the images are rendered properly.
In your deployment process, after calling collectstatic, you'd call the new management command.
Again, this is one option. There are probably others.

Related

django custom database engine documentation

I'm making a django project where there is the need to use information from an ApiRest. To manage the information more easily I created classes to get the info and display it.
Since my classes aren't django models the relashionships between those and my database take a lot of work and will break with each change I make. So I want to use a custom database backend instead of the classes. But there I cant find any documentation on how it should be done.
Is there a place where I can find the documentation of how a database engine works in django?
I have already looked in the django docs but there is no article or section about database engines. Or I couldn't find it.
edit: added info
I'm looking to do something similar - Creating a custom database engine using pyodbc.
I found
https://www.youtube.com/watch?v=tkwZ1jG3XgA
https://simpleisbetterthancomplex.com/media/2016/11/db.pdf and
https://reinout.vanrees.org/weblog/2016/11/04/database-backends.html
as good documentation starting points.
Then I created https://pypi.org/project/django-filemaker-pyodbc/0.0.1/ after going through the documentation and reading through django_pyodbc

Execute management command from admin with arguments

My little podcast backend written in Django contains a ShowModel. I have also written a custom management command to update episodes for each show from an external API.
For ease of use I'd now like to put a button next to the list of shows in the Django admin to be able to update them from there. I know there's call_command() that also takes the argument but I'm getting a bit stuck in how to bring this into the admin area where the shows are already. Also, if possible I'd also pass the output to the web admin.
You can use this lib https://github.com/vint21h/django-mcadmin
Or try to read the code and pull some pieces to your project.
I was solving the same puzzle of running management commands from the admin interface, so here is what I found pip install -i https://test.pypi.org/simple/ django-run-command
This package helps you to run management commands from the admin dashboard

How to create views automatically from model as in Django admin?

I'm starting to use Django and I'm really impressed by the possibility of automatically creating views from a model.
So, I'd like to know if there is such functionality on other web frameworks. I know of RoR scaffolding, but that is not quite the same thing, since you need to change your views manually in case you change the related model.
For those who are looking for an answer here, perhaps django-baker (https://github.com/krisfields/django-baker.git) will do what you need.
pip install django-baker
Then add django_baker to INSTALLED_APPS and run
python manage.py bake your_app_name
Note that previously you need to remove urls.py and views.py from your app so they can be generated.
Then it will generate all the skeleton stuff.
https://docs.djangoproject.com/en/dev/topics/class-based-views/
I think I've found one possible solution. The concept is called model drive development. There are quite a few java frameworks that provide the ability to create a, rather simple, application directly from the model. This post presents some of them http://www.javaneverdie.com/java-frameworks/java-domain-driven-frameworks-review/

How to integrate multiple image uploading with UPLOADIFY in django administration?

I met the django-uploadify (multiple file uploading) application, but the only template-use is described in wiki of the project. I need to integrate it with django admin. Any ideas?
#rebus and #Mordi have good suggestions; one of those is probably your best bet. Still...
The current implementation of file uploads in web browsers is single file only. That's a limitation of the HTML standards and the browsers themselves. When you see multiple file upload capability (all at once / select multiple) in some web app, something like Flash or Java is in play. You could potentially use a Flash or Java applet (check out Uploadify - about the easiest to work with you'll find), if you wanted, but you'd have to do some work tying it into Django: namely mapping the output of the applet to the input the Django Admin expects on POST.
Personally I found this package to be painful when I attempted to do this locally. It is 7 years old and not maintained. django-filer is a more modern implementation that has this exact functionality built into the admin panel, it was quick to set up and it seems to be maintained a lot better. And the UI is excellent!
If your really set on using uploadify my attempt was quite painful. When I went to the website to download the uploadify jQuery plugin it was a paid download. After looking a bit I found a fork, and was able to get it going locally, but because the python package is old it required a lot of changes from python 2.7..
To integrate this with your project in the admin will definitely require you to write your own custom admin template. In your admin.py you would have to override the default template and methods, this faq has some insights. In your new template you would include the uploadify jquery script and put the upload file field inside the form where your model fields would be. When you upload files the signal sender in the package will fire, and you would just have to intercept the signal and handle it with your intended logic
Very easy to implement multiple image upload with this project:
https://github.com/tstone/django-uploadify

Pinax: Customize Signup and profile

I want to gather some more information when the user signs up and also display this as part of the profile information - so that the user can edit it once he creates a login.
How can I extend the sign-up and profile form and model without changing directly pinax code?
From pinax docs
Customization
As more sites are built using Pinax,
more best practices will emerge, but
for now what we recommend is:
Always work off a stable release. The most current release is 0.7.1.
Use the pinax-admin setup_project command.
Make necessary changes to the settings.py and urls.py files in your copied directory.
Change the domain and display name of the Site in the admin interface.
Develop your custom apps under your new project or anywhere on Python path.
Develop your own templates under your new project.
This thread is very relevant to your question and discusses options for overriding the default pinax apps.
It suggests looking at https://github.com/eldarion/idios, (an extensible profile app designed to replace the profiles apps in Pinax).
This blog has some comments about overriding the default pinax apps:
Overriding build-in Pinax Applications
Assuming we want to override
$PINAX_ROOT/apps/blog with
$PROJECT_ROOT/apps/blog we can do so
simply by copying the application and
make our project-local (read
individual) changes to it. Pinax will
then load $PROJECT_ROOT/apps/blog
rather than $PINAX_ROOT/apps/blog.
Those who do not care about merging in
upstream changes nor submitting
bugfixes/features upstream would just
issue cp -a $PINAX_ROOT/apps/blog
$PROJECT_ROOT/apps and be done. Those
who consider themselves good
FLOSS-country citizens however care
about contributing back as well ...
The default pinax apps you would be looking to override (if necessary), would be:
http://pinaxproject.com/docs/dev/apps/account/
http://pinaxproject.com/docs/dev/apps/profiles/
You probably want to have a go at overriding the built-in Pinax applications, which is gone over in a little detail in this article. I imagine you'd want to extend (or override) Pinax's Profile model.
This chap seems to have been in a situation that sounds like what you want, have a quick read of his chat logs to see what I mean. Sorry that this answer isn't too specific, it's more of a pointer.