Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jon Earley
    @jonearley
    This message was deleted
    Olexandr Shalakhin
    @shalakhin
    I have such code in forms.py:
        colors = forms.MultipleChoiceField(
            choices=[
                (color.id, color.name) for color in Color.objects.all()
            ],
            widget=forms.CheckboxSelectMultiple, required=False)
        categories = forms.MultipleChoiceField(
            choices=[
                (category.id, category.name) for category in Category.objects.all()
            ],
            widget=forms.CheckboxSelectMultiple, required=False)
    If I try to run migration I get errors
    that there is no such database table as Color or Category
    How should I write such things to not have to comment something in forms.py?
    Jussi Räsänen
    @jrasanen
    Do you have a model for color / category?
    Olexandr Shalakhin
    @shalakhin
    Yes
    and I have migrations
    Jussi Räsänen
    @jrasanen
    can you do Color.objects.all() in django shell?
    or do you get an error
    Olexandr Shalakhin
    @shalakhin
    I have model in code but no tables. Database is clean
    to create tables I need to run migrations
    but manage.py migrate gives me an error that there is no such table
    Jussi Räsänen
    @jrasanen
    Run make migrations?
    What do you have in your models? What’s the error?
    Olexandr Shalakhin
    @shalakhin
    Imagine you write you project. You write model and generate migration. Then you run migration and it fails to run because in forms.py you used model for choices
    Dan Gamble
    @dan-gamble
    Don't you have to move that code into the __init__ method?
    Olexandr Shalakhin
    @shalakhin
    Maybe I am not alone in such problem so I wonder what is the best practice here? Maybe I did it the wrong way.. I guess comprehension executes query and it failes
    I put forms logic in forms.py file
    Dan Gamble
    @dan-gamble
    I've had the problem before and i fixed it by moving it to the form __init__
    Olexandr Shalakhin
    @shalakhin
    hm, I will try. Thank you
    Puneet Aggarwal
    @puneetagg
    Hi...
    Please help me in finding error in the following as Django is unable to recognize get_queryset() method:
    class UserPostList(generics.ListAPIView):
        model = Post
        serializer_class = PostSerializer
        logging.debug("hello")
    
        def get_queryset(self):
            queryset = super(UserPostList, self).get_queryset()
            return queryset.filter(author__username=self.kwargs.get('username'))
    Nasaruddin
    @pace-noge
    This message was deleted
    Are you using DRF?
    agusmakmun
    @agusmakmun

    somebody can help me how to add class active for html templates, eg: nav menus, bassed in generic.ListView?

    some idea i was try with {% if request.resolver_match.url_name == "name" %} and {% if request.get_full_path == '/mypage/' %} but it isn't work.. i think may it because pagination in generic.ListView...

    any idea how to solved it?

    Puneet Aggarwal
    @puneetagg
    @pace-noge Yes.
    Nasaruddin
    @pace-noge

    @agusmakmun how about using templatetags?, for example:
    assuming your url like this:

    url(r'^direktorat/$', DirektoratListView.as_view(), name="direktorat-list"),

    templatetags

    from django import template
    
    register = template.Library()
    
    @register.simple_tag
    def active(request, pattern):
        import re
        if re.search(pattern, request.path):
            return "active"
        return ""

    then you can use it at template like this:

    {% load active %} # load the templatetags
    {% url 'direktorat-list' as direktorat_list_url %}  #save it as variable for future change
    
    <!-- link -->
    <li class="{% active request direktorat_list_url %}"><a href="{{ direktorat_list_url }}">Direktorat</a></li>
    Nasaruddin
    @pace-noge
    @puneetagg how about:
        def get_queryset(self):
            return Post.objects.filter(author__username=self.kwargs.get('username'))
    agusmakmun
    @agusmakmun

    @pace-noge woow... that was awesome, i never think it with templatetags before..

    {% load nav_menus_active_tags %}{% url 'direktorat-list' as direktorat_list_url %}
              <li class="{% if request.resolver_match.url_name == "popular_videos_page" %}{% active request direktorat_list_url %}{% endif %}">

    thank you so much.. :smile:

    agusmakmun
    @agusmakmun
    ups.. update it:
    {% load nav_menus_active_tags %}
    {% url 'popular_videos_page' as popular_videos_page %}
       <li class="{% if request.resolver_match.url_name == "popular_videos_page" %}{% active request popular_videos_page %}{% endif %}">
          <a class="nav-popular" href="{% url 'popular_videos_page' %}">Popular</a>
       </li>
    agusmakmun
    @agusmakmun

    @pace-noge but, are it possible with multiple path?
    egg: html li have some childs like a dropdown. if one of child selected then li will add to class active.

    egg:

    <li><a href="#">Settings</a>
       <ul>
          <li><a href="#">Profile</a></li>
          <li><a href="#">Change Password</a></li>
       </ul>
    </li>
    Puneet Aggarwal
    @puneetagg
    @pace-noge Thanks for the reply. Facing some other problem. Will check it later.
    Colin Wirz
    @cwirz
    Hey guys does anyone know what is the normal memory usage of a django 'it works' site? I see on my mac that the usage is 20-30 mb. Find it really to much fo doing nothing. What do you think?
    cs89gr
    @cs89gr

    0
    down vote
    favorite
    i want to create django project with two templates main list and details from the main list using genetic views List view and details views. the main list work but not work details list. this my code can somebody to help me ?

    urls.py

    urlpatterns = [
    url(r'^$', ListView.as_view(
    model = Test,
    queryset = Test.objects.all(),
    context_object_name = "test_list",
    template_name='blog\test_list.html')),

    url((r'^(?P<pk>\d+)-(?P<slug>[-\w]+)/$', DetailView.as_view(
    context_object_name="test_list1",
    model=Test,
    template_name='blog\Test_details.html'
    ), name="test"),

    ]
    html code test_list

    {% for test in test_list %}

    <h2> <a href="{{test.id}}">{{test.Title}}</a></h2>
    {% endfor %}
    html code test_details

    <h2>{{ test.Title }}</h2>
    .......................

    Muhammad Taqi Hassan
    @muhammadtaqi
    Need a Good Article/Tutorial for Working in Backbone.js in Django?
    cs89gr
    @cs89gr
    i find it
    Muhammad Taqi Hassan
    @muhammadtaqi
    What?
    cs89gr
    @cs89gr
    for my ask before
    Muhammad Taqi Hassan
    @muhammadtaqi
    Good, you are solving the issues yourself. that's a good habit and will help you alot.
    cs89gr
    @cs89gr
    yes i try for lern it
    Puneet Aggarwal
    @puneetagg
    Hi..
    Is get_validation_exclusions method of ModelSerializer in Django Rest Framework removed in latest versions?
    If yes, whats the alternative?
    Muhammad Taqi Hassan
    @muhammadtaqi
    Em looking for good resource for learning Node.js with django?
    Kaushal Kumar
    @kaushal087
    How can I get server's base address in django
    kdelinx
    @kdelinx
    @kaushal087 "Smoke" to the way - self.request.path
    ikhahmedov
    @ikhahmedov

    Hi all!

    I am making web app, when user sees web page for the first time, going to create User for him/her with some random name/pwd and set it in SESSION, everytime user loads page, it feels like he already registered, whenever user wants to sign up, I will offer REST API to change his/her username/pwd then reload this session, do you think this is good solution or are there any other way doing this?

    P.S. Asked in DjangoGirls/tutorial also
    P.S. Sorry for my broken English, I am not a native speaker and can create some ambiguous sentences

    Nicholas Penny
    @nickpennyuk
    Hi, I have an error that has stumped me
    I am fairly new, have finished a django tutorial and am now taking the next steps by myself to learn from here on. When adding {% url 'artist_new' %} to an anchor in my HTML I'm getting a NoreverseMatch highlighting the above django url. Any thoughts?
    ikhahmedov
    @ikhahmedov
    search for name='artist_new' in your urls.py file, if no then you didn't specify url name, which {% url ... %} tag uses