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!

  • install
    • If the plugin would be installed the needed plugin model tables would be created automatic
  • deinstall
    • If a plugin would be deinstalled, the existing model tables would be droped, too!

requirements

  • The model class must have a Meta class and must defined app_label = 'PyLucidPlugins'!
  • The plugin module must set the variable PLUGIN_MODELS contains a list or tuple of all models.

example

 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?)

links