我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.contrib.admin.sites.site()。
def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'rrule': kwargs['widget'] = RecurringEventWidget( text_field='rrule', start_date_field='start_date') elif db_field.name == 'start_date': kwargs['widget'] = DateInput() elif db_field.name == 'start_time': kwargs['widget'] = TimeInput() elif db_field.name == 'duration': kwargs['widget'] = MinuteField() elif db_field.name == 'place': formfield = super(EventDateInline, self).formfield_for_dbfield(db_field, **kwargs) widget = EditableForeignKeyRawIdWidget(db_field.rel, site) formfield.widget = widget return formfield return super(EventDateInline, self).formfield_for_dbfield( db_field, **kwargs)
def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'rrule': kwargs['widget'] = RecurringEventWidget( text_field='rrule', start_date_field='start_date') elif db_field.name in ('description', 'discount_info'): kwargs['widget'] = CKEditorWidget( config_name='simple_paragraph') elif db_field.name in ['key_image', 'logo']: formfield = super(EventAdmin, self).formfield_for_dbfield(db_field, **kwargs) widget = ForeignKeyRawIdWidgetWrapper(formfield.widget) formfield.widget = widget return formfield elif db_field.name in ('parent', 'place'): formfield = super(EventAdmin, self).formfield_for_dbfield(db_field, **kwargs) widget = EditableForeignKeyRawIdWidget(db_field.rel, site) formfield.widget = widget return formfield return super(EventAdmin, self).formfield_for_dbfield(db_field, **kwargs)
def __init__(self, rel, queryset, to_field_name, *args, **kwargs): self.rel = rel self.queryset = queryset self.limit_choices_to = kwargs.pop('limit_choices_to', None) self.to_field_name = to_field_name self.max_value = None self.min_value = None kwargs.pop('widget', None) forms.Field.__init__(self, widget=self.widget(rel, site), *args, **kwargs)
def __init__(self, rel, queryset, to_field_name, *args, **kwargs): self.rel = rel self.queryset = queryset self.to_field_name = to_field_name self.max_value = None self.min_value = None kwargs.pop('widget', None) super(AdminFileFormField, self).__init__(queryset, widget=self.widget(rel, site), *args, **kwargs)
def register(*models, **kwargs): """ Registers the given model(s) classes and wrapped ModelAdmin class with admin site: @register(Author) class AuthorAdmin(admin.ModelAdmin): pass A kwarg of `site` can be passed as the admin site, otherwise the default admin site will be used. """ from django.contrib.admin import ModelAdmin from django.contrib.admin.sites import site, AdminSite def _model_admin_wrapper(admin_class): admin_site = kwargs.pop('site', site) if not isinstance(admin_site, AdminSite): raise ValueError('site must subclass AdminSite') if not issubclass(admin_class, ModelAdmin): raise ValueError('Wrapped class must subclass ModelAdmin.') admin_site.register(models, admin_class=admin_class) return admin_class return _model_admin_wrapper
def autodiscover(): autodiscover_modules('admin', register_to=site)
def register(*models, **kwargs): """ Registers the given model(s) classes and wrapped ModelAdmin class with admin site: @register(Author) class AuthorAdmin(admin.ModelAdmin): pass A kwarg of `site` can be passed as the admin site, otherwise the default admin site will be used. """ from django.contrib.admin import ModelAdmin from django.contrib.admin.sites import site, AdminSite def _model_admin_wrapper(admin_class): if not models: raise ValueError('At least one model must be passed to register.') admin_site = kwargs.pop('site', site) if not isinstance(admin_site, AdminSite): raise ValueError('site must subclass AdminSite') if not issubclass(admin_class, ModelAdmin): raise ValueError('Wrapped class must subclass ModelAdmin.') admin_site.register(models, admin_class=admin_class) return admin_class return _model_admin_wrapper
def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name in ('description', 'hours'): return db_field.formfield(widget=CKEditorWidget( config_name='simple_paragraph', )) elif db_field.name == 'place': formfield = super(PlaceAdmin, self).formfield_for_dbfield(db_field, **kwargs) widget = EditableForeignKeyRawIdWidget(db_field.rel, site) formfield.widget = widget return formfield return super(PlaceAdmin, self).formfield_for_dbfield(db_field, **kwargs)
def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'entity': formfield = super(EventEntityInline, self).formfield_for_dbfield(db_field, **kwargs) widget = EditableForeignKeyRawIdWidget(db_field.rel, site) formfield.widget = widget return formfield return super(EventEntityInline, self).formfield_for_dbfield( db_field, **kwargs)