Extending Customer's view from Django-Oscar - python

I am trying to override customer app in django-oscar. For that I have created customer app in my apps folder in project. While I run that project I encountered an error in django 1.7.4 as below:
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: customer
I went through the doc in django https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig, But its not working out. So Is there any other way to extend any django-oscar's app and modify the code as per requirements.
This is my customer app's views.py:
from oscar.apps.customer.views import ProfileView as CoreProfileView
class ProfileView(CoreProfileView):
template_name = 'new_account.html'
and below is project's settings.py code snippet:
INSTALLED_APPS = [
'apps.customer',
]
Thanks in advance.

Run this command to overide apps from django oscar
./manage.py oscar_fork_app appname yourprojectname
yourprojectname-Your folder path to where the app should be created
Once you run this command a new app will be created with overided models,admin files.now add the app path inside
get_core_apps(['yourproject.order']) in settings.py file.
For more information please refer
http://django-oscar.readthedocs.org/en/latest/topics/customisation.html

Related

configuring django admin on elastic beanstalk

I am having a hard time configuring django admin to work on elastic beanstalk. I tried everything but it's still not working.
when I click on admin or my flag pages I get Server Error (500).
I have created a folder in my project called management in the root of my project, inside that I created another folder called commands and a file called createsu.py here is the content of the createsu.py
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
class Command(BaseCommand):
def handle(self, *args, **options):
if not User.objects.filter(username="admin").exists():
User.objects.create_superuser("admin", "admin#admin.com", "admin")
self.stdout.write(self.style.SUCCESS('Successfully created new super user'))
in my .config file I added this like of code
03_createsu:
command: "python manage.py createsu"
leader_only: true
after eb deploy and refreshing elastic beanstalk console when I try to go to the webpage I still get the same error. all my other pages are working, static files are working fine except my admin and flag pages because they are connected to the admin. I have been struggling with this for a week now. can someone please help me please.
#I fixed the issue.
#First typo was I forgot to add SITE_ID = 1 in my settings.py because I am using #flatpages.
#Second typo I didn't configure my static files correctly. I fixed it to this:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'assets'),
)
#Lastly createsu.py should be in the app folder not project folder.

Django django.contrib.sites where to put migration?

the django doc says to change the sites name and domain in the django.contrib.sites framework one should use a migration [1].
But they forgot to mention where I should put this migration. I tried to create a directory named "sites" and a directory named "django.contrib.sites". But no matter in which directory I put my migration, manage.py migration always says there is nothing to update.
I also tried to run python manage.py makemigrations --empty sites, but then the migration is created in the lib directory: ve/lib/python3.5/site-packages/django/contrib/sites/migrations/0003_auto_20160904_2144.py. This may be correct behaviour, but then I cannot set my change under source control.
In case something is wrong with my migration, here it is:
from __future__ import unicode_literals
from django.db import migrations, models
def set_site_name(apps, schema_editor):
Sites = apps.get_model('django.contrib.sites', 'site')
site = Sites.objects.filter(id=1).first()
if site != None:
site.name = "name"
site.domain = "name.com"
class Migration(migrations.Migration):
initial = True
operations = [
migrations.RunPython(set_site_name),
]
So my question is: where does django expect to find those migrations?
Thank you very much in advance for your help.
[1] https://docs.djangoproject.com/en/1.10/ref/contrib/sites/#enabling-the-sites-framework
Each app in a Django project must have a unique label. Naming your app sites isn't a good idea - it will clash with the django.contrib.sites app unless you change the label in the app config class.
If you have an existing app specific to your project, you could use that app to store the data migration.
Alternatively choose a different name like mysites. Create the app with ./manage.py startapp mysite, add the app to your INSTALLED_APPS, then create a blank migration.

how to update django admin

I have an app named polls in Project A,and it's in admin too, but I added an app named pingpong later, I added the app pingpong in the installed_app and synced database(it works), but the admin page is still the same. So how do I do to make the admin page update?
You have to add your models in admin.py
from pingpong.models import YourModel
admin.site.register(YourModel)

How can I use Flask Admin panel in a different package?

This is my application structure:
/blog
/blog
/app.py
models.py
views.py
/admin
__init__py
views.py
...
I want to use flask-admin extension in a different package.
in /admin/__init__.py I imported the app and flask-admin extension:
from flask.ext.admin import Admin
from app import app
then I initiate the admin app like that:
admin = Admin(app)
However, I get 404 error. Why? Should I use blueprint or what?
I assume you're trying to hit the default /admin routes within your Flask app for Flask admin?
My guess right now is that none of your code does import admin anywhere, which is probably good since admin's __init__.py will try to re-import your app.py all over again (from the from app import app reference) and you'll end up in a circular dependency.
What I'd do is alter app.py to contain the admin = Admin(app) and from flask.ext.admin import Admin code, and also do a from admin import views and empty out the admin/__init__.py file completely.

Django 1.5.2 Admin site no add or change buttons

I have a blog app inside of my own website app. The blog's objects (Posts, Comments) don't have the Add/Change buttons in the admin interface.
I used to have the admin code inside of my blog/models.py, but after reading this post I have moved the admin code in a separate file named blog/admin.py which looks like this:
from django.contrib import admin
from myapp.blog.models import Post, Comment
class PostAdmin(admin.ModelAdmin):
search_fields = ["title"]
admin.site.register(Post, PostAdmin)
class CommentAdmin(admin.ModelAdmin):
display_fields = ["post", "author", "created"]
admin.site.register(Comment, CommentAdmin)
However despite this change the add/edit buttons are still absent. I have admin.autodiscover() in my main app's urls.py. I also have admin as an installed app.
You should run below command after your changes
python manage.py syncdb
#then
python manage.py runserver
into your project root directory.
Edited
You must check your permission column into User section and make sure blog(add/edit/delete) option is given to that user .

Categories