How to integrate Django-CMS into an existing project - python

I need to integrate Django-CMS 3.x into an existing project (mypjc hereafter). I already checked this question (and other similar) but they point to a tutorial page that is no longer available.
I'm a bit confused by the tons of infos you can find online and I have not really understood if Django-CMS can be integrated as an app into an existing and independently running Django project.
mypjc (using Django 1.8) would benefit from a user friendly CMS. Basically I'd the user to be able to write texts and to load in their posts images stored in the (common) database, images that are created by the user in mypjc.
Is it possible? if yes, could anyone help me defying the steps needed to make the integration clean and successful?
Thank you in advance for any help you could provide.

With Django CMS, it is indeed possible to integrate it into an existing project.
If you already have an existing project with URL/menu management, then you can simply integrate just the per-page CMS, which can be added as additional field to your model:
from django.db import models
from cms.models.fields import PlaceholderField
class MyModel(models.Model):
# your fields
my_placeholder = PlaceholderField('placeholder_name')
# your methods
You can find more information here.
For any existing projects, you are likely to need to use the manual installation process outlined here.

Related

contenttypes framework in Django

I am reading Django documentation (https://docs.djangoproject.com/en/3.0/ref/contrib/contenttypes/#module-django.contrib.contenttypes).
I did not understand content type app, the Django docs describe it as below
Django includes a contenttypes application that can track all of the models installed in your Django-powered project, providing a high-level, generic interface for working with your models.
Can someone explain this from beginner perspective ?
I have experience in developing websites in Django but never touched in this app.
Example: you want to make user-related logging, something like an audit module in user profile. You have dozen of models that could be logged. User, Order, Task, Product, etc.
So your main model will be something like AuditEntity.
How to make it general for all possible current (and future models) that could be logged here? Which type of field do you need?
The answer is Django contenttypes.
If you want - try to implement such a model's structure to understand how it works.
I think that what is trying to tell you is that you can have different content (in blocks, as it is organized in "blocks" and it is very "module friendly", I hope to give the idea), this content is made up of different things, especially models, let's just say that they are like big classes of things needed in your application (don't judge this expression, I know it is not professional but is the more beginner friendly I can write now), hope this makes more clear!

Django: other options than models.TextField() for articles

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.

Django Flowchart Model

Is anyone aware of a Django app for designing and storing flowcharts in a database? After searching for variations of "Django flowcharts", I've only found flowcharts of Django's internal design, not anything about authoring or storing flowcharts in a Django webapp.
As asked in a similar question, I've found several impressive Javascript and JQuery based libraries for browser-based flowchart design, but nothing for persisting these server-side.
I wrote an app that stores and controls state machines in Django 1.2:
https://bitbucket.org/canassa/zinaflow
It uses a per-object permission model for controlling the transitions and GenericForeignKeys for attaching the state machine to any model in your application. With the per-object permissions you can assign a Django user for each transition.
Depending on what you need to do, this app might be a overkill for you. But reading the source code can give you some ideias on how to implement an app yourself.
Why couldn't you do it yourself? The behavior and presentation is already implemented in the several truly impressive JavaScript libraries you've referenced, now all that's left to be done is to store the models in the database for your favorite pick you'd like to persist through Django.
There is a library that implements Modified Preorder Tree Traversal on the model level that I'm sure would be of great use to you to store the logical relations between the flowchart elements and other presentation data, such as the coordinates, shape, it's transformations and other visual properties can be easily stored alongside.
I'm sure that if you'd give it some thought you could quickly execute it; hell it's even probable that there are many people who need the same thing, which would make it even more useful if you weren't developing it just for yourself. This seems like a good candidate for an OS Django app.
I am not aware of an existing app that does this, but if you want to start developing your own a good place to start would be exploring the code for GraphModels, a command from the excellent django-command-extensions project. It is a django manage.py extension that creates database diagrams from models using graphviz.

Django Pinax , extending bundled applications

I want to use Pinax for a small project , but I am confused because I don't if can extend/change the behavior and functional of the provided applications .
Is there any documentation for extending the behavior of the bundled applications ?
example: in registration application ,I want to add custom fields but I am not able to find proper documentation on how to achieve it..( mainly for those which need db changes )
Thanks !
Yes, you can extend the behaviour of the built-in applications. If you are using the pinax basic setup with user accounts and profiles, you will have to add the extra fields you want in apps/profiles/models.py. For a list of field types, see here: https://docs.djangoproject.com/en/1.3/ref/models/fields/
This will create the necessary db fields for you when you run manage.py syncdb. If you have already sync'd the db, however, you will have to manually add the db columns. If you don't have any data you care about in that table, you can always just drop the table and it will recreate it. Django doesn't modify db tables once they are created, even if you change the model.
You will also have to modify the signup form to include these new fields and point your urls.py to the new signup form you created. Copy the form from the site-packages/pinax directory to your project. Don't modify them directly.
If you haven't already, you should check out the Django tutorial here: https://docs.djangoproject.com/en/1.3/intro/tutorial01/
This will give you a good idea of how Django apps are put together and how the different pieces interact, so you can do a better job customizing Pinax to your liking. Make sure you know what models.py, urls.py, views.py, and the templates are doing.

Linking google-appengine native model to Django model

I've ported my GAE project to django-nonrel, and now I would like to have link from my object to Django User object:
class Opinion(google.appengine.ext.db.Model):
...
author = db.ReferenceProperty(django.contrib.auth.User)
Unfortunately, that's not possible, since you only can link GAE models this way.
Question - what's the best way to solve this? Is it possible or should I work it around somehow?
I don't want to migrate my old GAE model since I already have a bunch of data there.
My initial googling and searching brought me nothing good:
On django-nonrel list I read:
You cannot use appengine model into django-nonrel. You need alter all
your models to django proper. That is, use original
django-registration app not the appengine-patch provided registration.
Another question, exactly like mine, was left unanswered.
... and I've found another place where people recommend switching to Django models.
I guess that's that then, there is no way of doing what I need, one needs to migrate.

Categories