How to save blog editing history? - python

I have a blog website using django and I keep editing blogs occasionally, and I want to retrieve a history version at any time just like git and notes history function in evernote.
How can I do that? Should I save every new version in the database?
Are there any good solutions? Any language is welcome (python, java, ...).
Example:https://blog.evernote.com/blog/2010/04/14/new-premium-features-note-history-and-50mb-notes/

Yeah this can be done by adding a Django LogEntry. LogEntry is the model used by Django to maintain the Django admin edit history. You can use the same model to track changes to your blog.
Refer to this Stackoverflow answer on how to use it.
https://stackoverflow.com/a/988202/1774657

Django/Python version:
I would make two models: FirstBlog() and EditedBlog() and bind them via OnetoMany together.
everytime you edit the FirstBlog() version, you create another EditedBlog() version with information: who edited it, when edited, what edited.

Related

Creating an REST API Django [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
The first thing that I would like to say is that I have no previous experience with python and any framework python related. However, I have programming experience.
So, I want to create a REST API using python with frameworks django and djangorestframework. I have managed to create the database (using postgresql) and also managed to create the initial migration. However, I believe that that was the easiest part and I have some questions about the thing that I'm about to implement:
First I want to create an authentication system. I saw that djangorestframework it's able to manage authentication by itself but I was not able to make it run. Can you please guide me to some good tutorials/provide code samples and briefly explain?
After initial migration, I saw that django created some tables for authentication and session management by itself (auth_user, auth_user_groups, etc). Is there any way to use my own model for user? Also, i do believe that I wont need all the features that django offerrs (e.g auth_user_groups). Its there any way to remove those unwanted functionalities?
I was able to create an API endpoint (by following a tutorial) that returns some data (based on a model, a serializer and a view created by me). However, as I want to create more API endpoints I have also to create a serializer and view for each model of mine (which might take a while). Is there any way to create a generic serializer and a generic view method so I don't need to write a specific serializer and a view method (e.g I would like to GET models by /api/books/book/:id, where book its just a placeholder for any model)?
P.S. If this post lacks any informations please let me know in a comment and I will edit this post.
Okay, let's see:
Documentation is your best friend. This is especially true in case of Django which has great documentation. Generally, there are three ways to use authentication in Django:
Default User class (django.contrib.auth.user.models) just works out of the box.
You can extend it by creating other model (like Profile) and linking it via OneToOneField.
Alternatively, you can provide your own User class via subclassing (usually AbstractBaseUser) and registering it in Django's settings.
Finally, you can write completely custom backend.
For customization guide consult this article.
For the first part of the question see paragraph above. Regarding removing user groups: its probably possible (though I've never tried it), but I don't see much point. It has practically no overhead whatsoever while providing some useful stuff like staff/admin groups for Django's admin panel.
Absolutely there is a generic solution. Just use generic API views. Again, I'm linking documentation. In short, you want to use subclasses of GenericAPIView class.
For instance, let's say to want to list User objects under /users/ path:
url(r'^/users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
For your particular example you would use RetrieveAPIView. If you want to look it up with pk you don't even have to configure it.

Using Django admin as a base for backend

First sorry for my poor English.
I came from asp.net mvc. Now I use django with nanoboxio
In asp, I can create sections like below.
Create model and add it to dbcontext
Right click controller folder and create new controller with views.
Modify as you wish
For now, I know Django can create admin interface for your model. I try and happy with it. but i want to develop it.
I want to for example;
Create a post model.
Create a admin interface for it.
Copy generated admin interface controller and views to another app
Modify it
How can I do that?
Django's MVC is quite different to ASP.
Django's MVC pattern is less strict so you sort of combine the view and the controller in the views.py. However, if you want to change the Admin, the Django docs are quite nice here: docs.djangoproject.com
If you want to create a custom admin functionality the docs should give you a first idea and if you're planning to create a blog, I would advice you to use an existing plugin such as Zinnia. There, you can find the desired functionalities and modify them instead of building them from scratch.
Also, there are a couple of tutorials on how to build reusable apps and they usually include a detailed guideline how to implement admin functionalities there. Just look it up on google.
I hope that helps you!

Create an estimator tool in Django Python

I am new to Django. I have read the official documentations and managed to create models in Django. I have a task to create an estimator tool that could provide the estimate(cost) to the user when he selects the hardware/softwares etc. This could be something similar to this http://calculator.s3.amazonaws.com/index.html. This is only for reference but I want to add details dynamically.
Basically I am curious to know about:
How to add rows in Django?
How is the 'Monthly cost' working in amazon calculator?
I want to achieve something similar to this dynamic estimations.
Any pointers/articles/suggestions will be helpful in my learning and analysis.
You have to override the Django admin template for that.
How to add button next to Add User button in Django Admin Site
for auto-selecting the group value you can use
https://github.com/crucialfelix/django-ajax-selects

How to add a datagrid using django?

I'm trying to learn django since I'm newbie in it.
One task that I'm about to do is adding a custom datagrid into a webpage.
The things that datagrid needs to have are:
connection to a model
The queries to the database (edit, delete, add)
A search box
First of all I need to know how to add a datagrid. Is there any django-lib except dojango that could be suitable for me?
I have already read dojango lib.
I'm using django version 1.8
Any helper is welcome to share the knowledge.
Thanks and appreciate
Sounds like the Django Admin is perfect for your needs.

How to use Django with existing database?

I want to create the admin for some tables of an existing MySQL dabatase. I want to use Django since it is just one line of code - admin.site.register(TableName) - so I save a lot of time coding the admin from scratch. I looked here for the inspectdb option of Django https://docs.djangoproject.com/en/1.5/howto/legacy-databases/ but only in the development version https://docs.djangoproject.com/en/dev/howto/legacy-databases/ says something about managing the inspected model. I want to know if it is possible and if somebody tried to work with an existing database before but not for read only, I want to manage and edit these database from my Django application.
If you're not using the development version, don't read the docs for that version. All they say is that - new in that version only - models created via inspectdb will by default be marked as managed = False, which means that they can't be modified. But the docs go on to describe exactly how you can modify them, simply by changing that setting.
But of course, you should be using the latest stable version, 1.5, which doesn't do that anyway. You can add and edit items in models from a legacy db to your heart's content.

Categories

Resources