Giter Site home page Giter Site logo

cb_dj_select2's People

Contributors

akjasim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cb_dj_select2's Issues

Wont' work on Class Based Views

Hi,

Thanks for making the project available.
Is there a way to make the project also available in class based views?

Everything is the same except for the urls and the following class based view:

class EntryCreateView(CreateView):
    model = Entry
    fields = "__all__"
    template_name = 'class_django_select.html'
    success_url = reverse_lazy('index')

    def post (self, request, *args, **kwargs):
        if request.is_ajax():
            print ("ajax request")
            term = request.GET.get('term')
            languages = Language.objects.all().filter(title__icontains=term)
            return JsonResponse(list(languages.values()), safe=False)

        return super().post(request, *args, **kwargs)

Unfortunately, it doesn't work as expected.

Is there a way around this?

AttributeError: 'WSGIRequest' object has no attribute 'is_ajax'

When cloning this project and using the latest version of Django==4.0.6, I get the above error.

I followed the solution from https://stackoverflow.com/questions/70419441/attributeerror-wsgirequest-object-has-no-attribute-is-ajax which fixed it nice and easy.

In views.py,

def is_ajax(request):
    return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'

def home(request):
    form = EntryCreationForm(instance=Entry.objects.first())
    if is_ajax(request):

Warning models.W042 on both tables

Not a big deal but the project gives the following warnings when running;

WARNINGS:
core.Entry: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.        
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the CoreConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
core.Language: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.     
        HINT: Configure the DEFAULT_AUTO_FIELD setting or the CoreConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'

I chose to add a pk;

models.py


from django.db import models

# Create your models here.


class Language(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=56)

    def __str__(self):
        return self.title


class Entry(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=124)
    language = models.ForeignKey(Language, on_delete=models.CASCADE, verbose_name="Favourite Language")

    def __str__(self):
        return self.name

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.