Parcourir la source

Haz alterntive data

Marcos Dumay de Medeiros il y a 9 ans
Parent
commit
87be6f7213
3 fichiers modifiés avec 27 ajouts et 3 suppressions
  1. 14 0
      src/rapid/wrappers.py
  2. 8 2
      testproject/testproject/models.py
  3. 5 1
      testproject/testproject/urls.py

+ 14 - 0
src/rapid/wrappers.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+from django.contrib.contenttypes.fields import GenericForeignKey
 from django.contrib.contenttypes.models import ContentType
 
 __author__ = 'marcos.medeiros'
@@ -163,7 +164,20 @@ class ModelData:
     def all_fields(self):
         r = []
         relations = []
+        ignore_fields = []
         for f in itertools.chain(self.local_fields(), self.related_fields()):
+            if f.bare_name() in ignore_fields:
+                ignore_fields.remove(f.bare_name())
+                continue
+            if isinstance(f.field, rapidfields.AlternativeDataTables):
+                for ff in self.rapid_alternative_data():
+                    if ff[1].ct_field == f.bare_name():
+                        f = FieldData(ff[1])
+                        for fr in r:
+                            if fr.bare_name() == ff[1].fk_field:
+                                r.remove(fr)
+                        ignore_fields.append(ff[1].fk_field)
+                        break
             if f.is_relation():
                 relations.append(f)
             else:

+ 8 - 2
testproject/testproject/models.py

@@ -9,9 +9,17 @@ from rapid import rapidfields
 class AltData1(models.Model):
     name = models.CharField(max_length=30)
 
+    def __unicode__(self):
+        return 'name: ' + self.name
+
+
 class AltData2(models.Model):
     upd_date = models.DateField(auto_now=True)
 
+    def __unicode__(self):
+        return 'upd_date: ' + self.upd_date
+
+
 class Test1(models.Model):
     some_text = models.CharField(max_length=30)
     some_int = models.IntegerField()
@@ -21,5 +29,3 @@ class Test1(models.Model):
     alt_data_type = rapidfields.AlternativeDataTables((AltData1, AltData2))
     alt_data_id = models.PositiveIntegerField()
     alt_data = rapidfields.AlternativeData('alt_data_type', 'alt_data_id')
-
-

+ 5 - 1
testproject/testproject/urls.py

@@ -6,10 +6,14 @@ from testproject import models
 from rapid import register
 from rapid import permissions
 
+cruds = [models.Test1, models.AltData1, models.AltData2]
+
 urlpatterns = [
     url(r'^/?$', views.blank),
     url(r'^login$', login),
     url(r'^logout$', logout, {'next_page': '/'}),
     url(r'^applications/', include('rapid.urls')),
-] + register.model(models.Test1, permissions.to_all(), permissions.to_all())
+]
 
+for m in cruds:
+    urlpatterns += register.model(m, permissions.to_all(), permissions.to_all())