Ways to get AuditTrail data in Django - python

I'd like to know what's the best way to get data from AuditTrail table in views.
I'd like to show all the versions of a model's fields using a template and a view. I looked for a way to show it in admin area but I had no success.

look at Django reversion https://github.com/etianen/django-reversion
It should do what you need.

Related

What are the ways to make it possible to change banner image of site directly through django admin?

I know how to make it possible to create/edit/delete a multiple-row database model through django admin page. But let's say I want to make it possible to modify the single banner image of my site through admin page, what am I supposed to do then?
Should I create an entire database model for one item? Or is there a better way to implement this?
You can either create your own model for these types of settings, or you can use one of the many packages designed to handle this type of situation:
https://djangopackages.org/grids/g/live-setting/

Sort Columns in Django Templates

I know I should put up some code with what I've tried but I don't know where to start.
In Django admin I can display data so that it can be sorted by the user using:
class MyModelAdmin(admin.ModelAdmin):
list_display = ['field1', 'field2']
ordering = ['field2','field1']
Within the admin site, users will be able to click the top of the column and reorder on that column.
I want to replicate this functionality in an non-admin screen. How do I do that?
You have two approaches available:
Import and modify the admin templates to use their sortable functionality. This answer covers the basics very well., but the ModelAdmin class has a lot of functionality, which you may or may not actually need. You can start from the admin templates more generally if you want to go down that route.
Use an external library to manage in the templates.
I find the latter approach is actually easier, faster and more easily extensible. I have just implemented this in a project using datatables, which takes a couple of minutes, assuming you already have a table.

How to edit data with django-tables2 in a frontend?

I have a Django and i want to create CRM system, allowing users to view, add, delete and edit data in a front-end. I found nice module, named django-tables2, which allows displaying nice tables of my data:
django-tables2 turns data into HTML tables. Features:
Pagination Ordering Extendable Class based view Supports for queryset
and list data Themes
So my question is what is the best way to make front-end editing with this tables?
For example: i want to make records from table be selectable with checkboxes and then i want them to be deletable and editable, like in django built-in admin. In other words: i need some tool like django-admin but in my front-end (in my template).
So do i need to write js to handle user clicks on table records and point this actions to my urls/views or there is a better way?Hope this question will help not only my but anyone who planning to became frontend-ninja, THANKS!
I think you should take a look at Swampdragon and Angular. They might integrate nicely with django-tables2. You can always just write the table with Angular.

Custom Django Database Frontend

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

How to have a change list in django that filters by a field having a relation?

Suppose I have two models:
class Blog(models.Model):
pass
class Article(models.Model):
blog = models.ForeignKey(Blog, related_name="articles")
I want to filter only blogs that have an article. The filter would be something like this:
Blog.objects.annotate(article_count=models.Count('articles')).filter(article_count__gt=0)
How can I have the change list at the admin filter like this?
I tried a few approaches, like custom filterspecs, but had no success.
The best solution was to use a proxy model and register a separated admin list, like this solution:
Multiple ModelAdmins/views for same model in Django admin
But that doesn't work very well with the permission system.
Any ideas?
There's currently no way, aside from some very painful hacks, to accomplish that. Django 1.4 will ship with the ability to create custom filterspecs (see: https://code.djangoproject.com/ticket/5833), which will allow you to do stuff like this.
Since this seems to be kind of an edge case (really, how many blogs will ever have zero posts for a significant period of time?) My suggestion would be to just hold out for now, and maybe look into upgrading once 1.4 is released.
If you insist on going down the rabbit hole, you can start here: Custom Filter in Django Admin on Django 1.3 or below

Categories

Resources