-2

Question how can I pass the value from get_sheet_header class into another method basically I want to the set a HTML response header and my pk then drop it down into another method I use any help would be greatly appreciated and any questions please let me know.

Here is what I have so far

views.py

**#here is where I want to pass the value to my get_sheet_header class** 

def update_sheet(request, pk=None): 
    obj = get_object_or_404(Sheet, pk=pk) 
    form = SheetUpdateForm(request.POST or None, 
                        request.FILES or None, instance=obj) 
    if request.method == 'POST': 
        if form.is_valid(): 
           form.save() 
           return redirect('sheet_update.html') 


    response = render(request, 'app/sheet_update.html', 
      { 
         'sheet_form': form, 
         'title':'Update Sheet', 
      }) 
    response['SHEET_ID'] = pk 
    get_sheet_header.sheet_header(get_sheet_header(pk)) 
    return response 

**#here is my get_sheet_header class** 

class get_sheet_header(object): 
   def __init__(self, s_id): 
     self.s_id = s_id 

   def sheet_header(self): 
      s = self.s_id 
      return s 

**#here is where I want to use the value that the above returns ^** 

def add_dimensions(request, pk): 
  pk = get_sheet_header() #this should be the return value from my get_sheet_header class 
Snowman08
  • 425
  • 1
  • 4
  • 16
  • Your class get_sheet_header looks more like a function than a class. You prob want to have the the class be the SheetHeader or be the Sheet itself. – Jeff Mandell Aug 03 '16 at 15:44
  • It looks like you're trying to use sheet_header as a static method when it's defined like a member method? See http://stackoverflow.com/q/735975/2800918 – CAB Aug 03 '16 at 15:44

2 Answers2

0

Just create direct instance of your class and then call method.

tmp_obj = get_sheet_header(obj)
pk = tmp_obj.sheet_reader()
Kirill
  • 67
  • 9
-1

So instead of making this overly complicated like I was doing. I decided to dumb it down and do it this way and it works :).

def update_sheet(request, pk=None):
  blahh blah...
  global = SHEET_HEADER_ID

  SHEET_HEADER_ID = pk 


def add_dimension(request, pk):
   pk = SHEET_HEADER_ID 
Snowman08
  • 425
  • 1
  • 4
  • 16