I've already created my simple blog in Python Django.
For now, I am interested how to maintain two languages on my blog.
I know about Django internationalization but I do not want to translate button text in my templates.
I've created post model with several fields for different languages: description_ru, description_en. At the end of the day, I want to show fields based on user language preference.
What best practices now (in 2017) to that. Many projects seem to be out of date now;-(
Maybe I should create separate apps for different languages?
Thanks in advance.
Related
So in the Django tutorials we make a sparse polls application that shows off some of what Django can do, but leaves a lot to be desired when it comes to learning Django (e.g. using their UserCreationForm to make a user portal).
In part of the tutorial they talk about how the admin should be publishing content (e.g. if it were a blog or newspaper) and we set up the admin site where one can make new questions for the polls.
In regard to the blog idea - since an article would be lengthy most likely - I think the correct model would include models.TextField. However, looking at Django's naturally generated admin site for adding / modifying new models with a TextField leaves a lot to be desired.
What if there should be images embedded among the text? or what if there should be formatted text? The admin site does not support a user friendly way to do this.
My question is how to produce a user friendly way for making mixed media e.g. a Stack Exchange post which might have images, code formatting, text formats, etc.
You could use Django Pagedown which aims exactly to offer a way of editing similar to that found on stackexchange sites. As for now you cannot yet upload images (this feature is though on the todos list of the author), they must be already uploaded somewhere on the web and you can insert them using their url.
I wrote a django project that is some kind of a CMS.
Now, I want to be able to create several accounts that use that CMS, Each with a different database.
For example, user can create himself an account in my service - and he will get a site based of that CMS.
How can I get started doing this?
Look at the django docs https://docs.djangoproject.com/en/dev/topics/db/multi-db/ There are is useful example. Another good article https://thenewcircle.com/s/post/1242/django_multiple_database_support
Unfortunately Django is not suited to dynamically switch databases at runtime. You either have to implement really hackish solutions (like mentioned in this question Django multiple and dynamic databases ) or to go with several independent Django instances which you will have to start up on your server dynamically.
A much simpler solution would be to stick to one database and distinguish different users' content by some other means, like Django Sites framework. The only problem with this approach in my opinion is that you will have to carefully set up your admin site configuration, so that users don't see each other's objects (in case you planned to use built-in Django admin).
I'm very new to django and python as well. I want to try out a project written in django.
Let say the project have 3 modules
User
CRUD
Forgot password
login
Booking
CRUD
Search
Default (basically is for web users to view)
Home page
about us
All these have different business logic for the same entity.
Should I create 3 apps for this? If 3 different apps, then the table name is all different as it will automatic add a prefix for table name.
Any suggestion?
There's really no correct answer to this. In general, the way in which you break down any programming task into 'modules' is very much a matter of personal taste.
My own view on the subject is to start with a single module, and only break it into smaller modules when it becomes 'necessary', e.g. when a single module becomes excessively large.
With respect to the apps, if all the apps share the same database tables, you'll probably find it easier to do everything in a single app. I think using multiple Django apps is only really necessary when you want to share the same app between multiple projects.
I agree in #aya answer and I also supported your structure for multiple modules. In my project, I created 18 apps. Each app perform different rules:
1. accounts
- login
- forgot password
- register
- profile
2. common
//in here all the common function use by different apps
3. front
- home
- testimonial
4. guides
//tutorials
And lots more apps...
I arrange this way so that it will be easy to trace, debug, and find the codes. If your problem is the name of table you can set the class Meta of db_table.
I am relatively new to Django and Python myself too. In practice, try to have your Django apps do one thing and do it well. If you find that an app is becoming more and more complex, it may be worth splitting this out into multiple apps.
I would not worry about the DB tablename as Django handles the DB interaction for you. If you name your apps and models well, your code should be fairly self documenting.
I have recently learnt a lot of "best practices" in how to setup and layout Django projects from the ebook 2 Scoops of Django. I am not affiliated with them in any way, but have just learnt a lot from it.
Also, definitely run through the Django tutorial if you haven't already.
Hope this has helped!
Focus on making your apps reusable. This way you will save significant number of time in your next project. Good article about it is available at the Django's website.
If you have closely integrated modules or depending on each other, then there's no real benefit of having them in separate apps, because you won't ever use them separately. Organizing in separate Python modules will be just fine.
Also do not think about "how will my tables be named" when you consider project organization. Tables can be easily renamed while bad design will make you trouble as the project will grow.
I have a model that has multiple text properties - title, short and long description etc. I want to have multilanguage site so I need a way to easy by able to add new languages and translations for this field for every item. What is the best way to achieve this?
Django has built-in support for I18N (read internationalization):
http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/
Some possible multilingual model candidates:
http://code.google.com/p/django-multilingual-model/
http://and-other-things.blogspot.com/2009/04/list-of-django-multilingual-model.html
I found that django transmeta, also listed by The Myyn is actually quite right for what llian is looking for. We have a very similar setup in production for some of our high traffic websites.
Does anyone know of a django forum plugin that allows each member to have his own forum? If there isn't anything, than what would be the best way to accomplish this with a "regular" forum plugin for Django?
I once created a feature matrix of all Django forum apps I could find. It might be a bit outdated now, though (contributions welcome).
At least django-threadedcomments uses generic foreign keys, so you can attach a message thread to any database object, including users.
Look at DjangoBB.
Yep, the forum app of SCT can be used for this - simply set it up and create multiple "community Groups" (these are similar to vhosts) and map them to subdomains - each community group would have separate forum categories, can have separate templates, separate user permissions, etc. (but they will obviously share the same django users and their profiles) - as an example.. the following websites are all hosted on the same instance:
SCT website
My personal website/blog (the blog is also based on SCTs forum)
ShelfShare Community
Check out diamanda. I'm not sure it does what you need as far as the each user having its forums, but that's probably not too hard to hack on top. Probably as simple as adding a few ForeignKeys into auth.User to the diamanda models. In general django pluggables and djangoapps are good places to look for django stuff that is already written. Also, check out pinax.
I believe the Sphene Community Tools can do this.