def custom_context(view: DetailView): obj = view.get_object() Foreign = namedtuple('Foreign', ['model_name', 'id', 'to_one']) _custom_context = { 'fields': [ field.set( value=getattr(obj, field.name) ) if not field.is_foreign else field.set( value=Foreign( model_name=field.type.field.related_model.__name__.lower(), id=getattr(obj, field.type.field.related_model.__name__.lower() + '_id'), to_one=getattr(obj, field.type.field.related_model.__name__.lower()), )) for field in self.fields ], 'connections': [] } for connection in self.connections: connection_objects = connection.using.objects.all().filter( Q(**{snakecase(view.model.__name__) + '_id': obj.id}) ) for i in range(len(connection_objects)): connection_objects[i].model_name = connection.using.__name__.lower() connection_objects[i].connected_model_name = connection.to_one.__name__.lower() connection_objects[i].connected_object_id = \ getattr(connection_objects[i], snakecase(connection.to_one.__name__) + '_id') _custom_context['connections'] += connection_objects return _custom_context
def get_object(self, queryset=None): obj = DetailView.get_object(self, queryset) fbuserinroles = FBUserInRole.objects.filter(role__name=obj.name) obj.current_fbusers = [] for f in fbuserinroles: try: u = FBUser.objects.get(fb_userid=f.fb_userid) obj.current_fbusers.append(u) except MultipleObjectsReturned as mor: logger.error("Multi objets returned for fb_userid: %s.", f.fb_userid) logger.exception(mor) continue except ObjectDoesNotExist: obj.current_fbusers.append({ 'fb_userid': f.fb_userid, 'unknown': True }) return obj
def get_object(self, queryset=None): if queryset is None: queryset = self.queryset return DetailView.get_object(self, queryset)
def get_object(self): obj = DetailView.get_object(self) obj.people = LabInfo.objects.using('physics').filter(lab=obj.id) return obj
def get_object(self, queryset=None): self.object = DetailView.get_object( self, queryset=self.related_class.objects.all()) return self.object