django best practice for use different project using both some models - django

i need to create 2 project a little related.
i need to use for both project some apps and models. and maybe the same settings. using different templates and domains.
can do you recommend me?

Depending on how independent your projects are, there are two different solutions.
As karthikr reccomended, there is the sites package. If what you have in mind is really multiple projects that are very similar, but with different content and templates depending on the domain or URL, this is what you are looking for.
If what you have in mind is creating apps that you can reuse in multiple different projects, think about "reusable apps".
Python, and hence django, is inherently modular. This means that it is really easy to create and use apps, and to import them whenever you need them. Have a look at django's documentation on reusable apps:
https://docs.djangoproject.com/en/dev/intro/reusable-apps/
For some useful advice on app design and re-usability, have a look at James Bennett's (old but not completely outdated) talk at DjangoCon 2008: https://www.youtube.com/watch?v=A-S0tqpPga4

Related

Integrating django apps in your own views

Let's say I'm writing a complex site in django with wikis, forums, ... or writing my own apps that I intend to reuse from different sites.
I really want to create, for example, a wiki page that has a forum at the bottom, or reuse my previously written wiki app with a different graphical layout.
What is the best way to structure my app to allow this kind of reuse?
So far, I have been giving apps their own urls in urls.py. This however does not work if I want to combine multiple apps together in a single page.
Additionally, most of the apps I found online come with their own templates, which has the full html, and do not separate the logic of creating / preparing a context from that of handling a request and generating a reply.
What is the best practice here? What do you do? edit the templates that come from applications you download online? refactor them to fit in your application?
what should I do for my own applications? structure them so they have a method to get the context, and a method to render it?
Django hasn't great support out of the box to component-oriented architectures. I find this problematic some times too. You'll face to problems here.
Architecture
Code
Architecture: As Django is not component oriented, all the apps aren't component oriented neither. The designers and coders for those apps haven't thought about that. So they've just built "views" to interface with their apps. You'll need to get something more "pluggable".
Code: Once you decide to build that, you'll have to find what support you have for that. Most Django apps are pretty well coded, so you won't have much code in views, but abstracted in other places. That way you could reuse that code and build your own components.
Example: Suppose you're working with a third-party Wiki app. That wiki has a view to display highest ranked Tags and other view to create a wiki entry. If the code is good enough (that I'm assuming it is because Django has a pretty good community), you could refactor that to use components. The view to create an entry must be using some Form, that you can plug in your own site. And the view to get highest ranked tags probably uses some utility function, or some Tag manager's method. In that case you could refactor it to your own needs.
Hope it helps.

Choosing Django v1.4 app for tagging and categorization

I was looking for a tagging/categorization app for a Django project. In past I have used django-tagging and django-taggit. Looks like they are not being actively maintained. I also saw a few others but they are either unmaintained of don't really reach the functionality of these two.
The kind of project I was working on for past year did not require tagging like functionality therefore I am out of touch in this area.
So before starting on writing my own app I thought, I would ask the mighty Stackoverflow community if there are any maintained forks of these apps or if there others similar to them.
Thanks in advance.
I've used both on different projects, too with different Django versions. There are some forks to. For instance, for django-tagging there is django-tagging-ng that provides multilingual, synonyms and hierarchy.
I would simply refer to opencomparison for package comparisons of django apps here - http://django.opencomparison.org/grids/g/tagging/
And I would go with django-tagging and add in django-tagging-ext optionally.
Is this what you are looking for?
https://github.com/bkjones/django-taxonomy

better architecture in django is different apps. or single App for different components?

I have intended to have an app. where I want to have different things having relations with each other and want to know that whether I should have them as just different models or as differnt apps. Obviously if this is student, teacher in LMS then they are necessary component of LMS while if this is Job, Professional and Company then there can be different things associated with a job , a professional can have his full profile with different features, company can have different directory listing e.t.c. like features.
So Company and professionals who are users also should be as diff. apps. and job as different app.? Will this way be fine? as Jobs app. don't always everywhere need to have professional data or employer all data other than just name. So it seems like it is more convenient to have them as diff. apps, so that it can be used somewhere else.So is that right way?
Or
As I also want this project to be flexible so will the above make it more complex? And should I just treat them as diff. models instead of diff. apps. as Company and Professional are users , for which django gives Profile features also. So is this right way?
Which way is better one?
thanks in advance.
There is no exact answer here, so it's my opinion.
It is always good to have several apps rather than one big app. Reasons:
apps becomes smaller and it's easier to maintain small pieces of code;
project structure becomes more clear, I just need to look at the file manager to see main parts of the project;
interaction between apps become explicit: easy to test and prevent unnecessary coupling.
Not every Django app should be pluggable. It's ok to have two apps that depend on each other (if you aren't going to distribute them seperately). It's like having two dependent functions: nothing is wrong with it.

high quality, complicated django projects to learn from

What are some of the opensource django projects that are well designed and written and could benefit learners. For example, if I want to learn more how classy generic views work in the field, I'd like to see how it's implemented in a large website.
ReviewBoard is one I have had a look at a couple times - https://github.com/reviewboard/reviewboard

Is splitting a large django app a good practice?

I have created a complex E-R diagram for a django site I'm developing. It maps to 11 tables in the database. The site has many features, so I would like to split it into multiple apps. The Django manual said that Django apps should be pluggable, but if I split the models into many apps, they would be dependant on each other. Is this a good practice? If not, how should I structure my application?
Thanks
I wouldn't worry over the statement about making apps pluggable. Sure, if it could be a useful app in other projects, you may want to - but nothing enforces this.
There is no harm in making internal apps dependent.
Personally, my project-specific apps live inside the project module (or for larger projects, inside a project.apps module). This way, you're not polluting the python import namespace with your one-time apps.
You could separate them out into self contained apps, and they would work within the context of your project.
You could also create each app so it's totally independent. This often takes a bit more work, a nice example of this is Django-tagging, which you can basically attach to any other object.
So yes, you can do it. However if the app is just for you it may not be worth the effort (IMHO) ;)