PyLucid CMS Logo

plugin models

Since changeset:1612 plugin can have his own django ORM models (called 'plugin models')!

You can insert model classes directly into the plugin module or create a separated models.py and import the models.

The plugin models are normal django ORM models with all features. You can insert relationships to other existing django/PyLucid models!

↑ requirements  #

↑ example  #

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from PyLucid.system.BasePlugin import PyLucidBasePlugin

from django.db import models

#_____________________________________________________________________________
# models

class Artist(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        app_label = 'PyLucidPlugins' # essential

class Album(models.Model):
    artist = models.ForeignKey(Artist)
    name = models.CharField(max_length=100)

    class Meta:
        app_label = 'PyLucidPlugins' # essential

# essential: a list of all plugin models:
PLUGIN_MODELS = (Artist, Album)

#_____________________________________________________________________________
# plugin

class example_plugin(PyLucidBasePlugin):
    def create(self):
        """
        You can use the models as normal django ORM models!
        """       
        artist = Artist(name="FooBar Artist")
        artist.save()
        
        album = Album(
            artist = artist,
            name = "FooBar Album",
        )
        album.save()
    
    def display(self):
        albums = Album.objects.all()
        ...

↑ more examples  #

A example implementation can you see here:

↑ limits  #

Editing the models into the django admin panle is not tested / supported (isn't it?)

0 Kommentare für 'plugin models':
    Es existiert kein Kommentar für 'plugin models'
Kommentar hinterlassen
tag navi django | model | models | orm | plugin | pylucid | tables

django-processinfo: 5.3 ms of 301.4 ms (1.7%)