Django, Where are the comments tables created? - django

When using Django's built in comment package, where is the table created when the database is synced? The model doesn't seem to be in the models.py file.
I seem to be very confused trying to implement this. I found some tutorials online but nonw of them seem to help and I can't get anything to work.
Anyone have any tips? Can anyone explain how it works?

django.contrib.comments is a reusable app packaged with Django. Reusable (sometimes called 3rd party, whether or not they are) apps have their own models.py, urls.py, etc. So if you'd like to look at a model from the comments package, browse your Django source directory. On Ubuntu, that would be something like ls /usr/lib/python2.6/django/contrib/comments.
When the sync command is run, it goes through all of the apps in your INSTALLED_APPS list in your project's settings.py, and uses their models.py files to generate database schema.
Though reusable apps can be a little confusing (especially overriding templates!) they allow for your code base to be way more modular.

If you have things configured correctly you will see:
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_comments
Creating table django_comment_flags
Also make sure you have SQLite(assuming you are using sqlite) installed and have added the django.contrib.comments to your INSTALLED_APPS

Related

Django Apps with shared model migrate to multi schemas Postgres

In a Django project, I have a few apps and one model-class will be created in one app's models.py and imported to another apps' models.py. then I run migrate for each app per one schema in Postgres, there is no error reported.
But the issue is the shared model will be migrated to all the schemas because (I assume this is the reason) I imported this model in each app's models.py.
Anyone knows How to avoid or solve this problem. Because I would like keep the model only stay in his original schema.
Or can I delete this model directly from each schema it appears?...without any side effects.
Please help, Thanks!
I found a better answer: Installing PostgreSQL Extension to all schemas.
should see this before.
Accidentally found the solution, just use 'public' schema for the app where models supposed to import to other apps.
Just for someone who experience the same situation.

Have I to delete SQLite database from the directory after migrating to PostgreSQL on Django 2.2?

I am new to Django 2.2 and I found that SQLite is default database engine here. But I want to use the PostgreSQL instead of SQLite.
I have created a new project and migrate the (ex: Post) model after creating and adding the app to the settings.py and admin.py file. And after that, I decided to use the postgreSQL, and I did it too by migrating to postgreSQL. Before migrating I created a postgres database and add all the necessary details to the settings.py file's DATABASE settings according to instruction of Django. It's working fine. I haven't got any problem yet. Though I see still the sqlite database file still in the project directory. It looks bit odd though. I'm new to Django. Can you please tell me should I keep that file there or delete sqlitedb file? And is there any security issue with sqlitedb file if I keep there? I love to want a neat and clean project settings. Thanks in advance my dear friends!
It's totally up to you. If you want to keep then keep it. And if you want to delete that file delete it. There is no security reason or any problem will occur. Just delete it if you don't need it.
When to Use SQLite?
All applications that require portability and don’t require expansion.
In cases where applications need to read or write files to disk directly.
When to Use MySQL?
Where high-security features are required for data access.
For websites that work on MySQL despite some constraints.It's a
scalable tool that is easy to manage.

How to load django app models in a project without this project taking responsibility for migrations

Given the following architecture of django projects apps and database schemas:
There is a django app which I want to share between several django projects.
Each project has it's own postgresql schema in behind. All schemas live in the same postgresql database.
One project is owner of the apps data, this project is responsible to run migrations and the data should live in its schema.
All other projects may access the data from the other projects schema, because they have a proper postgresql search path set.
We already use this concept with an app that has all models set to unmanaged, which works. But database changes always needs to be done manually. I'd like to benefit from django migrations and therefore I want my models either managed or unmanaged.
Do you think app config is good place to change the models meta? Any other suggestions and approaches on how to solve the requirement are also welcome.
The in the comments mentioned setting MIGRATION_MODULES works very well. In those projects which should only access the data and which should not be responsible for the migrations you can easily disable the migrations like that:
MIGRATION_MODULES = {
'yoursharedapp': None
}
Note that you need to configure the postgresql role used in the those projects with proper grants and search path.

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/

Django not creating tables for an installed app

My django site was functioning before I installed Lion and had to reinstall everything related to development. Since then, I have deleted and recreated my database, but one of my two installed apps is being ignored in syncdb. Those tables are not present in my database.
This post suggested there might be an import error. I can import the app in question using manage.py shell, so I don't think that's it.
Both apps are definitely installed (verified by debug toolbar). Any other suggestions? I'm relatively new to Django, having been mostly an iOS developer for the past couple of years.
https://docs.djangoproject.com/en/dev/ref/models/options/#app-label
If a model exists outside of the standard models.py (for instance, if the app’s models are in submodules of myapp.models), the model must define which app it is part of.
What it doesn't mention is that they also have to be imported somewhere during the model registration phase.