w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to create two admin view and seperating the model between 2 admin views by using rails_admin gem
You cant achieve that using rails_admin. I've tried couple of months ago and found its not made for that. Currently I am using rails_admin for SuperAdmin as its required less customization. And I am using active_admin for normal administration.

Categories : Ruby On Rails

Active Admin Model Index Page (Model List View) define order of displayed fields
You should be able to define the fields to display in the index view inside the ActiveAdmin model configuration, i.e. ActiveAdmin.register Place do config.sort_order = 'name_asc' index do column :name column :address column :place_type column :published default_actions end end You can read more about ActiveAdmin options here: http://www.activeadmin.info/docs/3-index-pages.html

Categories : Ruby On Rails

How to filter admin list view for a given model dynamically in Django?
Either add a field to cache the result of average_severity() in a pre_save signal and use it in your queryset, either fall back to raw sql.

Categories : Django

How can I order the native django users in the django admin page based on creation time?
Shouldn't it just be: ordering = ['-date_joined'] You can order by any field the model gives you. Since you didn't specify the UserModel you are using, I guess you are talking about the BaseUser? If so, you can order by: first_name last_name id email date_joined username [is_staff] # bool [is_active] # bool

Categories : Python

Add new button for custom made order status to order view in Magento admin panel?
If you need to add an button like hold on order page you need to over write files app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php by using modules <rewrite> <sales_order_view>Namespace_Module_Block_Adminhtml_Sales_Order_View</sales_order_view> </rewrite> public function __construct() { parent::__construct(); $this->_addButton('your_button_id', array( 'label' => Mage::helper('xxx')->__('Some action'), 'onclick' => "setLocation('".$this->getUrl('*/*/Youbuttonfunction')."')",/* refere ref1*/ 'class' => 'go' ), 0, 100, 'header', 'header'); } ref1: you need to add Youbuttonfunction function in module controller perform your action and

Categories : Magento

model inheritance + django admin
You created a form for News, that also exist in your DB since the model is not abstract, not for MyNews. Thus your current form has no field for the departments attribute, even if you add a widget with an input for it. Do the code bellow instead: class MyNewsForm(NewsForm): class Meta: model = MyNews # instead of just News ... What Django does in background is to create two relations: the cmsplugin_news_news stores all the News fields, and the news_news_departments stores your new field and is in one-to-one relation with the first relation.

Categories : Django

Django admin tools new version model changes
After upgrading django admin tools I faced the same problem and ended up dropping tables admin_tools_dashboard_preferences and admin_tools_menu_bookmark and recreating them using python manage.py syncdb. Obviously, it will erase all custom parameters you may set before so make sure you made a backup.

Categories : Python

Django Model Class Missing in Admin
Your admin.py file should typically look like this. from django.contrib import admin admin.site.register(archive) admin.site.register(album) admin.site.register(image) Based on your admin.py I would do this. autoregister('archive', 'album', 'image') That said a few pointers - Your admin.py is a bit overly complicated and not needed when 3 lines will suffice. Additionally you should be naming your models in uppercase (Archive, Album, Image)

Categories : Python

Custom User Model in admin on Django 1.5
As you say, the UserCreationForm references auth.User directly. The Django docs on custom users and built in auth forms state that you must rewrite it for any custom user model. UserCreationForm Depends on the User model. Must be re-written for any custom user model. There is a related ticket Ticket 20086, which was initially closed as invalid, because the user creation form is working as documented. There is a full example on the same page, which shows you how to rewrite the forms and register a custom user model in the admin.

Categories : Python

django admin save_model not saving model changes
you have to call: obj.subscriptionInfo.save() as it's on a separate model, it will look something like this: def save_model(self, request, obj, form, change): #SUCCESS ACTIONS obj.subscriptionInfo.paid = 1 obj.subscriptionInfo.save() obj.save()

Categories : Python

How can I display a Django admin inline model within a fieldset?
Unfortunately this is not possible with (the standard template from) django. If you look at the template for the change_form, you can see that inlines are always rendered separately after the fieldset: https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/change_form.html The only work-around I see is to write a custom template with respect to the order you want.

Categories : Django

Django admin - TabularInline - display only a few objects from other model
formfield_for_foreignkey should do what you want: class InlineConnectn(admin.TabularInline): def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name == "book1": kwargs["queryset"] = Foo.objects.filter(book1__book_type=1) return super(InlineConnectn, self).formfield_for_foreignkey(db_field, request, **kwargs)

Categories : Python

Admin Site appending letter "s" to end of each model able name on Django
You should be setting verbose_name_plural in that case. Docs here. Also you should be setting it on the model's Meta options of your model (docs here). Example: class MyModel(models.Model): # my fields class Meta: verbose_name_plural="PluralForMyModel"

Categories : Django

How to make separate forms for one model in Django admin
Yes it is possible, do it like this: class MyModelAdmin(admin.ModelAdmin): def get_form(self, request, obj=None, **kwargs): if not obj: return MyModelCreateForm return super(MyModelAdmin, self).get_form(request, obj, **kwargs) Cheers! Please do not forget to up-vote if this answer was useful for you! ;)

Categories : Python

override django admin change_list_results.html per model
I was having the same issue and found this old post. I imagine you fixed yours. Anyways, what I was doing wrong was to use the plural name of the model and I was also using the lowercase name. You have to be sure of the following: Save your template in /templates/admin/APP/MODEL as you said Check your lower/upper cases in the names of the models This sounds silly, but just in case...Don't use the plural name of the model Good luck!

Categories : Django

Django: New class added in model.py not showing in admin site
Are you sure touching .wsgi file does restart your app? It looks like it doesn't. Make sure the app is restarted. Find the evidence touching .wsgi file restarts the app maybe. Since you don't provide any insight about how the dev server runs the apps, we won't be able to help you any further.

Categories : Django

Django Inline Model Admin filter Foreign Field
Django: accessing the model instance from within ModelAdmin? class PictureInlineForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PictureInlineForm, self).__init__(*args, **kwargs) self.fields['site'].queryset = Site.objects.filter( deal=self.instance.deal) class PictureInline(admin.ModelAdmin): form = PictureInlineForm

Categories : Django

Get value of field from referenced model displayed in Django Admin site
What you probably need is the list_display class ContractAdmin(admin.ModelAdmin): list_display('clientNumber', 'supplier') admin.register(Contract, ContractAdmin) To allow __ in Admin for foreign key, You can use this snippet From the snippet: from django.contrib import admin from django.db import models def getter_for_related_field(name, admin_order_field=None, short_description=None): """ Create a function that can be attached to a ModelAdmin to use as a list_display field, e.g: client__name = getter_for_related_field('client__name', short_description='Client') """ related_names = name.split('__') def getter(self, obj): for related_name in related_names: obj = getattr(obj, related_name) return obj getter.admin_or

Categories : Django

django admin - add custom form fields that are not part of the model
It it possible to do in the admin, but there is not a very straightforward way to it. Also, I would like to advice to keep most business logic in your models, so you won't be dependent on the Django Admin. Maybe it would be easier (and maybe even better) if you have the two seperate fields on your model. Then add a method on your model that combines them. For example: class MyModel(models.model): field1 = models.CharField(max_length=10) field2 = models.CharField(max_length=10) def combined_fields(self): return '{} {}'.format(self.field1, self.field2) Then in the admin you can add the combined_fields() as a readonly field: class MyModelAdmin(models.ModelAdmin): list_display = ('field1', 'field2', 'combined_fields') readonly_fields = ('combined_fields',)

Categories : Django

django poll tutorial admin not showing model edit
If you've correctly reproduced your code above, the problem is your indentation. It should be: class PillAdmin(admin.ModelAdmin): fieldsets = [ ('Drug information', {'fields': ['name']}), ] inlines = [AlarmInline] list_display = ('name') inlines is an attribute of the admin class - it and list_display need to be part of the class definition, not statements at the module level.

Categories : Django

Adding an external mongoengine model to Django-Admin views, is there a way?
I have used django-mongoadmin with some success for this. I was having a setup like yours, a normal Django installation with a MySQL database.. but had a few apps using mongoengine for better performance. This worked for me with simple CRUD-operations. Link: https://github.com/jschrewe/django-mongoadmin

Categories : Misc

Django custom user model in admin, relation "auth_user" does not exist
After some digging around I found this https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms The culprit is a function clean_username inside UserCreationForm inside django.contrib.auth.forms.py. A few tickets have been created, but apparently the maintainers don't think it's a defect: https://code.djangoproject.com/ticket/20188 https://code.djangoproject.com/ticket/20086 def clean_username(self): # Since User.username is unique, this check is redundant, # but it sets a nicer error message than the ORM. See #13147. username = self.cleaned_data["username"] try: User._default_manager.get(username=username) except User.DoesNotExist: return username raise forms.Valida

Categories : Django

How to save a related, inline django model when parent is saved in the admin?
First of all, the relationship you're describing is what called a ManyToMany "through" (you can read about it in the documentation here). Secondly, I don't understand why you need the 'hours' to be a field at all. Isn't a function enough for this? why save it in the database in the first place? you can just call it every time you need it. Finally, it seems to me you're doing a lot of extra work that I don't understand - why do you need the volunteer time boolean field? If you link a volunteer with an event isn't that enough to know that he was there? And what's the purpose of "counts_towards_volunteer_time"? I'm probably missing some of the logic here, but a lot of that seems wasteful.

Categories : Django

django link to a specific admin view
You can reverse admin list page url as follow: {% url 'admin:app_model_changelist' %} For other admin pages, see Reversing admin URLs from Django documentation.

Categories : Python

Extending Django Admin View not working
See the note box in the get_urls docs, which states that URLs there are included under the URL for the admin. So, assuming your app is HRMS and your model is EmployeePaySlip, that URL will be /admin/HRMS/employeepayslip/HRMS/mos/employeepayslip/, which probably isn't what you want.

Categories : Django

Create Django Objects outside of Admin
Sorry I am not sure about your question. If you want to have a unique field for your model you can do yourUniqueFieldName = models.TextField(max_length=100, unique=True) And this for a pair of (or more) unique fields you can do class Meta: unique_together = ('field1', 'field2',) Official documents is always your best friend as a start: https://docs.djangoproject.com/en/dev/ref/models/fields/

Categories : Python

Magento Admin Create Order needs to skip select Store
You can go directly to the product selection part of the create admin order process by this url: Mage::helper("adminhtml")->getUrl("adminhtml/sales_order_create",array("customer_id" => your_customer_id, "store_id"=> your_store_id)); You just have to call it by a button or by a form passing the store_id and customer_id parameters. Hope this helps.

Categories : Magento

django call admin.site.register from view
solution: from django.contrib import admin from polls.models import Poll from django.http import HttpResponse from django.shortcuts import redirect from django.core.urlresolvers import clear_url_caches from django.utils.importlib import import_module from django.conf import settings def index(request): admin.site.register(Poll) reload(import_module(settings.ROOT_URLCONF)) clear_url_caches() return redirect('/admin')

Categories : Django

Django Class view - only display if column 'admin' contains 1
This looks to me like a very basic Django question and I would recommend you learn how it works. class PictureCreateView(CreateView): model = Picture def form_valid(self, form): self.object = form.save() f = self.request.FILES.get('file') data = [{'url': settings.MEDIA_URL + "pictures/" + f.name.replace(" ", "_"), 'thumbnail_url': settings.MEDIA_URL + "pictures/" + f.name.replace(" ", "_"), 'delete_url': reverse('upload-delete', args=[self.object.id]), 'delete_type': "DELETE"}] response = JSONResponse(data, {}, response_mimetype(self.request)) response['Content-Disposition'] = 'inline; filename=files.json' return response def get_context_data(self, **kwargs): context = super(PictureCreateView, self).get_context_data(**k

Categories : Django

Django view doesn't display model value - Django 1.5
You're not giving the template an instance of Home. You need to create one and pass it to the template as a Context, in the form {'msg': msg}. EDIT: Adding some code First of all, you should create your instance of home in your view. I've never used TemplateViews, so I'm going to use a regular view method instead. def IndexView(request): home=Home.create("Hello World!") return render(request, 'index.html', {'home': home},)

Categories : Django

Raise django admin validation error from a custom view
Not sure I understood what you want well: You have a view, by definition a public page. You want it to display an error message in the admin pages (by definition privates page) ? It's odd. But if you want so. To display an error in the admin pages, use the Django Message Framework. It's what is in use to display the yellow rows with errors/notifications on the top of the pages. from django.contrib import messages messages.error(request, "Something goes wrong sending transaction mail"); Indeed, validation errors an only displayed with forms. And thus, they are to be raised only in the clean() method of a form, a formset, or a field.

Categories : Django

How to customize the list data view in Django admin interface?
You have to build your own view and add it to admin. Maybe the admin list_view is a good starting point. If this sounds too much of work, I could imagine three work arounds: Make a new column for each task and each deadline and add the tasks and dealines there like "task_taskname" etc. Of course, this will be too much information if you are haveing mor then two or three tasks in each project. Reverse your logic! Don't make a list_view for projects, but for tasks! You can still add the project name to this list. In fact, this is your current TaskAdmin. Generate the entrys for Task Name and Deadline using model functions. Additionally, give a short description like get_all_tasks.short_description = 'Task Name'. That should do the trick! Funny enough, your question might have triggerd s

Categories : Django

How can I add a button into django admin change list view page
First add the button. Django admin comes with jQuery so let's use it. Make a static file path/to/adminfix.js: (function($) { $(document).ready(function($) { $(".object-tools").append('<li><a href="/path/to/whatever/" class="addlink">Custom button</a></li>'); }); })(django.jQuery); In admin.py in your ModelAdmin: class Media: js = ('path/to/adminfix.js', ) Now create a custom view at "/path/to/whatever/". This can be a regular view (just like other pages on your website) or a custom admin view in Admin.py. The get_urls method on a ModelAdmin returns the URLs to be used for that ModelAdmin in the same way as a URLconf. Therefore you can extend them as documented in URL dispatcher: class MyModelAdmin(admin.ModelAdmin): def get_urls(self):

Categories : Django

django-polymorphic admin "cannot create 'NoneType' instances"
It turned out that specifying explicitly the form to use solved the problem: class ProjectForm(forms.ModelForm): class Meta: model = Project class ProjectChildAdmin(PolymorphicChildModelAdmin): base_model = Project base_form = ProjectForm For some reason the form is not automatically generated.

Categories : Python

Order Query in Django Model
By using order_by, like this: q = Post.objects.filter(public=True).order_by('like_count')

Categories : Python

django admin - select reverse foreign key relationships (not create, I want to add available)
Do you mean that for a given School instance you want to be able to get a list of all the students related to that school? In which case you use the related_name attribute of the ForeignKey relationship you specified. You haven't defined the related_name where you do: school = models.ForeignKey(School) which is fine, it just uses the default related name which is the name of the child class (student) followed by _set so for your school instance: school = School.objects.get(pk=1) students = school.student_set.all() # or .filter() or .exclude() etc then you can pass that student queryset into your template.

Categories : Python

How to create a custom date time widget for the django admin?
I think you can create a more generic widget. First, separate your js, html and media for create a unique widget. widgets.py class DatTimeField(forms.Textarea): def render(self, name, attrs = None): final_attrs = self.build_attrs(attrs,name=name) return "Here you have to return the html of your widget, for example: mark_safe(u'<input type=text %s value=%s class='your_css_class'/>' % (flatatt(final_attrs), value))" Now in your admin class, try this: class YourClassAdmin(admin.ModelAdmin): class Media: css = { "all": ("my_styles.css",) } js = ("my_code.js",) formfield_overrides = { models.DateTimeField : {'widget': DatTimeField()}, } If you want to customize your widgets, I suggest you to see the

Categories : Python

How would I create a CBV using django rest framework which will either retrieve a model instance or create a new one?
for classbased views in django-rest-framework this is usually done by: a GET request to the resource will retrieve records a POST request to the same resource will create a record I believe there are a couple examples of this in the django rest framework documentation

Categories : Django

Can we disply registered model forms side by side in Django Admin
Like this: class Employee_wage_detailsInline(admin.TabularInline): model = Employee_wage_details extra = 0 If it doesn't give you what you want, you need to modify change_form.html. Django Override Admin change_form.html Template - display associated model in template

Categories : Python

Two model forms in one view/template in Django using CBV
Code for view file : if request.method == "POST": company_form = CompanyEditForm(request.POST) if company_form.is_valid(): company_object = company_form.save() post_data = request.POST.copy() branch_form = BranchEditForm(post_data) branch_form.data['company'] = company_object if branch_form.is_valid(): branch_object.save() rest implement your business logic ..

Categories : Django



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.