Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:15:11+00:00 2026-06-04T13:15:11+00:00

I have a method: def get_netmask(user=None): user = User.objects.get(username=user) id_user = user.id obj =

  • 0

I have a method:

 def get_netmask(user=None):
     user = User.objects.get(username=user)
     id_user = user.id
     obj = Host.objects.get(user=id_user)
     obj = obj.ipv4_sub_net.distinct('ipv4_sub_net').order_by('ipv4_sub_net')

     # In this line i am getting an error: `'unicode' object has no
     # attribute 'distinct'` but the query is not complete . For full
     # question please follow the lines and given example

     return obj

Object of the Host model are ipv4_sub_net and ipv6_sub_net. My motive is for defining the above method is to get the value from ipv4_sub_net + ipv6_sub_net model field which will be fetched from Host model corresponding to a requesting user (loginned user). To do this i passed reuest.user.username to the get_netmask parameter at the time of calling it. Apart from that i also want to return the count os similar entry in ipv4_sub_net and ipv6_sub_net seperately.

For example:
In table there are four coloum present:

id      user_id        ipv4_sub_net       ipv6_sub_net
1       2              1.0.0.1             /23
2       2              8.9.7.3             /23
3       1              23.2.3.4            /43
4       2              1.0.0.1             /23

So, let’s say that the requesting user is with user_id 2. So according to method definitions it will return the dictionary. First index of dictionary contain unique IPv4_sub_net + ipv6_sub_net which is "1.0.0.1" and /23 and the second index will return the count of returning similar sub_net for ipv4 and the third index will return the count of similarsub_netfor ipv6 which2 for ipv4and2 for ipv6`.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:15:12+00:00Added an answer on June 4, 2026 at 1:15 pm

    Try changing

    obj = obj.ipv4_sub_net.distinct('ipv4_sub_net').order_by('ipv4_sub_net')
    

    to

    obj = obj.distinct('ipv4_sub_net').order_by('ipv4_sub_net')
    

    Edit

    On the first pass, I missed another error. You should also change

    obj = Host.objects.get(user=id_user)
    

    to

    obj = Host.objects.filter(user=id_user)
    

    get will always return a single object and throw an error if multiple objects are returned. If you’re expecting a single object, then I’m not really sure what you’re trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my messages_controller I have the following private method: def find_message_or_404(slug) message = user.messages.find_by_slug(slug)
I have a method: def fb_matches_for_friend_employer_goals(user, friend) User.where( :is_reachable_on_fb => true, # Users that
I have a User model in rails with the following method: def current_project if(self.active_project
I have a method which calls for a classmethod of another class def get_interface_params_by_mac(self,
I have a factory method that generates django form classes like so: def get_indicator_form(indicator,
I have a private method def __pickSide(self): in a parent class that I would
I have the following method: def call_http_service(url, url_params) begin conn = create_connection(url) resp =
I have ImageController with resize method: def resize = { def pht = Photos.findByTypeAndPhotourl(params.type,
I have the following application_controller method: def current_account @current_account ||= Account.find_by_subdomain(request.subdomain) end Should I
I'm new to Python. I have a method that begins: def foo(self, list): length

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.